Webos辅助插件

Webos辅助插件,用于对webos网页版的增强

目前為 2024-07-16 提交的版本,檢視 最新版本

// ==UserScript==
// @name         Webos辅助插件
// @namespace    https://gitee.com/fs185085781
// @version      1.0.1
// @description  Webos辅助插件,用于对webos网页版的增强
// @author       阿范🎈
// @include      *
// @icon         data:image/svg+xml,%3C?xml%20version=%271.0%27%20encoding=%27utf-8%27?%3E%3Csvg%20xmlns=%27http://www.w3.org/2000/svg%27%20viewBox=%270%200%20400%20400%27%3E%3Cg%20id=%27XMLID_273_%27%3E%3Cg%20id=%27XMLID_78_%27%3E%3Cpath%20id=%27XMLID_83_%27%20class=%27st0%27%20d=%27M304.8,0H95.2C42.6,0,0,42.6,0,95.2v209.6C0,357.4,42.6,400,95.2,400h209.6%20c52.6,0,95.2-42.6,95.2-95.2V95.2C400,42.6,357.4,0,304.8,0z%20M106.3,375C61.4,375,25,338.6,25,293.8c0-44.9,36.4-81.3,81.3-81.3%20c44.9,0,81.3,36.4,81.3,81.3C187.5,338.6,151.1,375,106.3,375z%20M293.8,375c-44.9,0-81.3-36.4-81.3-81.3%20c0-44.9,36.4-81.3,81.3-81.3c44.9,0,81.3,36.4,81.3,81.3C375,338.6,338.6,375,293.8,375z%27/%3E%3C/g%3E%3Cg%20id=%27XMLID_67_%27%20class=%27st2%27%3E%3Cpath%20id=%27XMLID_74_%27%20class=%27st3%27%20d=%27M304.8,0H95.2C42.6,0,0,42.6,0,95.2v209.6C0,357.4,42.6,400,95.2,400h209.6%20c52.6,0,95.2-42.6,95.2-95.2V95.2C400,42.6,357.4,0,304.8,0z%20M106.3,375C61.4,375,25,338.6,25,293.8c0-44.9,36.4-81.3,81.3-81.3%20c44.9,0,81.3,36.4,81.3,81.3C187.5,338.6,151.1,375,106.3,375z%20M293.8,375c-44.9,0-81.3-36.4-81.3-81.3%20c0-44.9,36.4-81.3,81.3-81.3c44.9,0,81.3,36.4,81.3,81.3C375,338.6,338.6,375,293.8,375z%27/%3E%3C/g%3E%3C/g%3E%3C/svg%3E
// @grant        GM_getValue
// @grant        GM_setValue
// @grant        GM_removeValueChangeListener
// @grant        GM_addValueChangeListener
// @grant        window.close
// @license      MIT
// ==/UserScript==
(function() {
    'use strict';
    let timeData = setInterval(function(){
        try{
            webos.addPanTokenGet = function(pName){
                return new Promise(function(success){
                    GM_setValue("setGetWebosToken","1");
                    GM_setValue(pName,"");
                    GM_removeValueChangeListener(pName);
                    GM_addValueChangeListener(pName,(name,oldValue,newValue,remote)=>{
                        success(newValue);
                    });
                });
            }
            clearInterval(timeData);
        }catch(e){
        }
    },100);
    setTimeout(function(){
        clearInterval(timeData);
    },10000);
    let lastCache = {};
    if(window.location.host.includes("mypikpak.com")){
        if(!document.cookie.includes("pp_access_to_visit=true")){
            document.cookie = "pp_access_to_visit=true"
        }
        if(GM_getValue("setGetWebosToken") == "1"){
            let oldFetch = fetch;
            unsafeWindow.fetch = function(...args){
                try{
                    if(args[0].includes("/v1/shield/captcha/init")){
                        let b = JSON.parse(args[1].body);
                        if(b.client_id && b.device_id && b.meta.captcha_sign && b.meta.timestamp){
                            lastCache.client_id = b.client_id;
                            lastCache.device_id = b.device_id;
                            lastCache.captcha_sign = b.meta.captcha_sign;
                            lastCache.sign_timestamp = b.meta.timestamp;
                        }
                    }
                }catch(e){
                }
                return oldFetch.apply(this,...args);
            }
        }
    }
    if(GM_getValue("setGetWebosToken") == "1"){
        if(window.location.host.includes("mypikpak.com")){
            (async function(){
                while(true){
                    if(lastCache.captcha_sign){
                        for (let i = 0; i < localStorage.length; i++) {
                            const key = localStorage.key(i);
                            if (key.includes("credentials_")) {
                                GM_setValue("setGetWebosToken","");
                                let param = JSON.parse(localStorage.getItem(key));
                                param.client_id = lastCache.client_id;
                                param.device_id = lastCache.device_id;
                                param.captcha_sign = lastCache.captcha_sign;
                                param.sign_timestamp = lastCache.sign_timestamp;
                                GM_setValue("pikpak",JSON.stringify(param));
                                lastCache = {};
                                top.close();
                            }
                        }
                    }
                    await new Promise(function(success){
                        setTimeout(function(){
                            success();
                        },100);
                    });
                }
            })()
            
        }
        var setRequestHeader = XMLHttpRequest.prototype.setRequestHeader;
        XMLHttpRequest.prototype.setRequestHeader = function (...args){
            if(args[0] == "Authorization"){
                this.auth = args[1].split(" ")[1];
            }
            return setRequestHeader.apply(this,args);
        }
        var open = XMLHttpRequest.prototype.open;
        XMLHttpRequest.prototype.open = function (...args){
            var that = this;
            let need = false;
            let data = {
                pan139:"yun.139.com/hcy/file/list",
                weiyun:"weiyunQdisk/DiskDirBatchList",
                lanzou:"doupload.php?uid"
            };
            for(let key in data){
                if(args[1].includes(data[key])){
                    need = true;
                    that.authKey = key;
                    break;
                }
            }
            if(need){
                let time = setInterval(function(){
                    if(that.readyState == 4){
                        clearInterval(time);
                        if(that.status == 200){
                            let token = null;
                            if(that.authKey == "pan139"){
                                token = that.auth;
                            }else if(that.authKey == "weiyun" || that.authKey == "lanzou"){
                                token = document.cookie;
                            }
                            if(token){
                                GM_setValue("setGetWebosToken","");
                                GM_setValue(that.authKey,token);
                                top.close();
                            }

                        }
                    }
                },100);
            }
            return open.apply(this,args);
        };
    }
})();