AutoUnlock

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

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

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

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 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);
        }
    }

}