sharer.pw auto click

auto click and redirect to download link immediately

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         sharer.pw auto click
// @namespace    https://github.com/x94fujo6rpg/SomeTampermonkeyScripts
// @version      0.2
// @description  auto click and redirect to download link immediately
// @author       x94fujo6
// @match        https://sharer.pw/file/*
// @grant        none
// ==/UserScript==

(function () {
    'use strict';

    window.onload = main();

    function main() {
        let idButton = setInterval(() => { watcherButton(idButton); }, 100);
        let idLink = setInterval(() => { watcherLink(idLink); }, 100);
    }

    function watcherButton(id) {
        let button = document.getElementById("btndl");
        if (!button) return;
        console.log(`stop ${watcherButton.name}(${id})`);
        clearInterval(id);
        button.click();
    }

    function watcherLink(id) {
        let links = getDownloadLink();
        if (!links) return;
        console.log(`stop ${watcherLink.name}(${id})`);
        clearInterval(id);
        if (links.length === 1) {
            window.location.href = links[0];
        } else {
            console.log("multiple links detected!! abort");
            console.log(links);
        }
    }

    function getDownloadLink() {
        let links = [];
        [...document.querySelectorAll("a")]
            .filter(e => e.textContent.includes("click here"))
            .forEach(e => links.push(e.href));
        if (links.length === 0) {
            return false;
        } else {
            return links;
        }
    }
})();