AutoUnlock

自动跳转并解锁百度网盘、Mega分享

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey, Greasemonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

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

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्क्रिप्ट व्यवस्थापक एक्स्टेंशन इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्क्रिप्ट व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्टाईल व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

// ==UserScript==
// @name         AutoUnlock
// @namespace    https://greasyfork.org/scripts/31324-autounlock
// @version      0.5.0
// @description  自动跳转并解锁百度网盘、Mega分享
// @author       MaiJZ
// @homepageURL  https://github.com/maijz128/AutoUnlock
// @supportURL   https://github.com/maijz128/AutoUnlock
// @match        *://pan.baidu.com/share/init?*
// @grant        none
// ==/UserScript==

/*
    百度网盘
        链接的格式:pan.baidu.com/share/init?surl=1miHVd8k&password=hg9j
        没有password不起效
*/

const Util = {
    hrefContains: function (str) {
        return location.href.indexOf(str) > 1;
    },
    GetQueryString: function (name) {
        var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
        var r = window.location.search.substr(1).match(reg);
        if (r !== null)
            return (r[2]);
        else
            return null;
    }
};


(function () {
    'use strict';
    run();
})();

function run() {
    var isBaiduShareInitSite = Util.hrefContains("pan.baidu.com/share/init");

    if (isBaiduShareInitSite) {
        BaiduPan();
    }
}




function BaiduPan() {
    if (Util.hrefContains("password=")) {
        unlockBaidu();
    }

    function unlockBaidu() {
        const value = Util.GetQueryString("password");
        if (value !== null || value !== "null") {
            var password = decodeURIComponent(value);
            console.log("password=" + password);
            _unlockBaidu(password);
        }
    }


    function _unlockBaidu(password, count) {
        const MAX_TIME = 10 * 1000;
        const INTERVAL = 50;
        const MAX_COUNT = MAX_TIME / INTERVAL;
        count = count || 1;

        console.log("password: " + password + " count: " + count);
        if (count < MAX_COUNT && password) {

            var inputs = document.querySelectorAll("input");
            var input = inputs[0];
            var submitBtn = document.querySelector("a[title='提取文件']");
            if (input && submitBtn) {
                input.value = password;
                submitBtn.click();
            }

            setTimeout(function () {
                _unlockBaidu(password, count + 1);
            }, INTERVAL);
        }
    }

}