Greasy Fork

百度云盘钥匙

百度云盘钥匙,打开云盘分享链接,自动填写云盘提取码

目前为 2018-10-17 提交的版本。查看 最新版本

// ==UserScript==
// @name         百度云盘钥匙
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  百度云盘钥匙,打开云盘分享链接,自动填写云盘提取码
// @author       Yisin
// @match        *://pan.baidu.com/*
// @require      https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.0/jquery.min.js
// @grant        GM_xmlhttpRequest
// @supportURL   meek.com.cn
// ==/UserScript==

(function() {
    'use strict';

    function getKey(){
        var key = "";
        var url = document.location.href;
        if(url.indexOf('//pan.baidu.com/s/') != -1){
           key = document.location.pathname.substring(4);
        } else if(url.indexOf('//pan.baidu.com/share/init') != -1){
           url = document.location.search;
           key = getUrlParam("surl");
        }
        return key;
    }

    function getUrlParam(param) {
        var reg = new RegExp("(" + param + ")=([^&#]*)", "g"),
            matched = location.href.match(reg);

        return matched && matched[0] ? matched[0].replace(param + "=", "") : null;
    }

    var weburl = document.location.href;
    var bdyKey = getKey();
    if(bdyKey){
        weburl = 'http://ypsuperkey.meek.com.cn/api/items/BDY-' + bdyKey + '?access_key=4fxNbkKKJX2pAm3b8AEu2zT5d2MbqGbD&client_version=web-client&' + new Date().getTime();
        GM_xmlhttpRequest({
            method: 'GET',
            url: weburl,
            headers: {"Accept": "application/json"},
            contentType: "application/json",
            dataType: 'json',
            onload: function(response){
                if(response.statusText == 'OK'){
                    try{
                         var res = JSON.parse(response.responseText);
                        $('.verify-input input').val(res.access_code);
                    }catch(e){}
                 }
            }
        });
    }

})();