AutoUnlock

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

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

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

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

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

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

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==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);
        }
    }

}