Greasy Fork

Greasy Fork is available in English.

夸克云盘

自定义提取码

当前为 2022-07-29 提交的版本,查看 最新版本

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

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

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

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

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。

您需要先安装用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         夸克云盘
// @namespace    http://tampermonkey.net/
// @version      0.2
// @description  自定义提取码
// @author       小怪
// @match        https://pan.quark.cn/s/*
// @match        https://pan.quark.cn/list*
// @connect      drive.quark.cn
// @connect      pan.quark.cn
// @icon         https://pan.quark.cn/favicon.ico
// @require      https://cdn.staticfile.org/jquery/3.6.0/jquery.min.js
// @run-at       document-body
// @grant        unsafeWindow
// @grant        GM_xmlhttpRequest
// ==/UserScript==

(function() {
    'use strict';
    unsafeWindow = unsafeWindow || window;
    var $ = $ || window.$;
    var quark = {

    };

    //分享页面
    quark.sharePage=function(){


    }

    //主页面
    quark.mainPage=function(){
        //监听
        (function(open) {
            XMLHttpRequest.prototype.open = function() {
                if (!this._hooked) {
                    this._hooked = true;
                    setupHook(this);
                }
                open.apply(this, arguments);
            }
        })(XMLHttpRequest.prototype.open);

        function setupHook(xhr) {
            (function setup() {
                Object.defineProperty(xhr, "response", {
                    get: function getter() {
                        delete xhr.response;
                        var responseURL = xhr.responseURL, response = xhr.response;
                        if (responseURL.includes("file/sort") && response) {

                            console.log(JSON.parse(response));

                        }
                        setup();
                        return response;
                    },
                    configurable: true
                });
            })();
        }



        //获取列表
        // quark.mainList();
        // console.log( quark.getItem("_share_args").value.stoken);

    }
    //获取列表
    quark.mainList=function(){
        var send = XMLHttpRequest.prototype.send;
        XMLHttpRequest.prototype.send = function(data) {
            this.addEventListener("load", function(event) {
                if (this.readyState == 4 && this.status == 200) {
                    var response = this.response, responseURL = this.responseURL;
                    if (responseURL.endsWith("file/sort")) {
                        try { response = JSON.parse(response) } catch (error) { };
                        if (response instanceof Object) {
                            console.log(JSON.parse(response));
                        }
                    }

                }
                else if (this.readyState == 4 && this.status == 403) {
                    if (obj.expires(this.responseURL) && obj.getItem("default_player") != "NativePlayer") {
                        var media_num = (this.responseURL.match(/media-(\d+)\.ts/) || [])[1] || 0;
                        if (media_num > 0 && obj.video_page.media_num != media_num) {
                            obj.video_page.media_num = media_num;
                            if (obj.getShareId()) {
                                obj.get_share_link_video_preview_play_info();
                            }
                            else {
                                obj.get_video_preview_play_info();
                            }
                        }
                    }
                }
            }, false);
            send.apply(this, arguments);
        };

    }

    //获取Storage
    quark.getItem = function(n) {
        n = window.localStorage.getItem(n)|| sessionStorage.getItem(n);;

        if (!n) {
            return null;
        }
        try {
            return JSON.parse(n);
        } catch (e) {
            return n;
        }
    };


    //自定义提取码
    //url_type=1 是没有提取码  2是提取码
    //
    quark.customSharePwd=function(){
        //监听
        $(document).on("DOMNodeInserted", ".ant-modal-root", function() {
            var text = $(this).find(".ant-modal-title").text();
            if (text == "分享文件") {
                if ($(".input-share-pwd").length == 0) {
                    var sharePwd = localStorage.getItem("share_pwd");
                    var html = '<div class="oper-row"><span class="oper-name" style="width: auto;">自定义提取码</span><span class="oper-area">';
                    //html += '<input type="text" class="ant-input input-share-pwd" value="' + (sharePwd ? sharePwd : "") + '" placeholder="" style="margin-left: 12px;width: 100px;height: 25px;line-height: normal;border: 1px solid #D4D7DE;text-align: center;"></div>'
                    html+='<input class="ant-input code-input input-share-pwd" type="text" value="' + (sharePwd ? sharePwd : "") + '" name="passcode"></span></div>';
                    $(".create-share-body").append(html);
                    sendSharePwd();
                }
            }

        });

        //判断获取的值
        function sendSharePwd () {
            (function(send) {
                XMLHttpRequest.prototype.send = function() {
                    if (arguments.length && typeof arguments[0] == "string" && arguments[0].includes("fid_list")) {
                        var share_pwd = localStorage.getItem("share_pwd");
                        if (share_pwd) {
                            var body = JSON.parse(arguments[0]);
                            body.passcode = share_pwd;
                            arguments[0] = JSON.stringify(body);

                            this.addEventListener("load", function() {
                                if (this.readyState == 4 && this.status == 200) {
                                    var url = this.responseURL;
                                    if (url.includes("/share?pr=ucpro&fr=pc")) {
                                        if (this.response.passcode == share_pwd) {
                                            quark.showTipSuccess("自定义分享密码 成功");
                                        }
                                        else {
                                            localStorage.removeItem("share_pwd");
                                            quark.showTipError("自定义分享密码 失败,请修改分享密码后重试");
                                        }
                                    }
                                }
                            }, false);
                       }
                    }
                    send.apply(this, arguments);
                };
            })(XMLHttpRequest.prototype.send);
        }


        //获取修改的值
        $(document).on("change", ".input-share-pwd", function () {
            var value = this.value;
            localStorage.setItem("share_pwd", value);
        });




    }

    //提示成功
    quark.showTipSuccess = function (msg, timeout) {
         quark.hideTip();
        var $element = $(".ant-message");
        if ($element.length) {
            console.log("存在");
            $element.html('<span><div class="ant-message-notice"><div class="ant-message-notice-content"><div class="ant-message-custom-content ant-message-success"><i aria-label="icon: check-circle" class="anticon anticon-check-circle"><svg viewBox="64 64 896 896" focusable="false" class="" data-icon="check-circle" width="1em" height="1em" fill="currentColor" aria-hidden="true"><path d="M512 64C264.6 64 64 264.6 64 512s200.6 448 448 448 448-200.6 448-448S759.4 64 512 64zm193.5 301.7l-210.6 292a31.8 31.8 0 0 1-51.7 0L318.5 484.9c-3.8-5.3 0-12.7 6.5-12.7h46.9c10.2 0 19.9 4.9 25.9 13.3l71.2 98.8 157.2-218c6-8.3 15.6-13.3 25.9-13.3H699c6.5 0 10.3 7.4 6.5 12.7z"></path></svg></i><span>'+msg+'</span></div></div></div></span>');
        }
        else {
            console.log("不存在");
            $(document.body).append('<div><div class="ant-message"><span><div class="ant-message-notice"><div class="ant-message-notice-content"><div class="ant-message-custom-content ant-message-success"><i aria-label="icon: check-circle" class="anticon anticon-check-circle"><svg viewBox="64 64 896 896" focusable="false" class="" data-icon="check-circle" width="1em" height="1em" fill="currentColor" aria-hidden="true"><path d="M512 64C264.6 64 64 264.6 64 512s200.6 448 448 448 448-200.6 448-448S759.4 64 512 64zm193.5 301.7l-210.6 292a31.8 31.8 0 0 1-51.7 0L318.5 484.9c-3.8-5.3 0-12.7 6.5-12.7h46.9c10.2 0 19.9 4.9 25.9 13.3l71.2 98.8 157.2-218c6-8.3 15.6-13.3 25.9-13.3H699c6.5 0 10.3 7.4 6.5 12.7z"></path></svg></i><span>' + msg + '</span></div></div></div></span></div></div>');
        }

        setTimeout(function () {
            quark.hideTip();
        }, timeout || 3000);
    };
    //提示失败
    quark.showTipError = function (msg, timeout) {
        quark.hideTip();
         var $element = $(".ant-message");
        if ($element.length) {
            $element.html('<span><div class="ant-message-notice"><div class="ant-message-notice-content"><div class="ant-message-custom-content ant-message-error"><i aria-label="icon: close-circle" class="anticon anticon-close-circle"><svg viewBox="64 64 896 896" focusable="false" class="" data-icon="close-circle" width="1em" height="1em" fill="currentColor" aria-hidden="true"><path d="M512 64C264.6 64 64 264.6 64 512s200.6 448 448 448 448-200.6 448-448S759.4 64 512 64zm165.4 618.2l-66-.3L512 563.4l-99.3 118.4-66.1.3c-4.4 0-8-3.5-8-8 0-1.9.7-3.7 1.9-5.2l130.1-155L340.5 359a8.32 8.32 0 0 1-1.9-5.2c0-4.4 3.6-8 8-8l66.1.3L512 464.6l99.3-118.4 66-.3c4.4 0 8 3.5 8 8 0 1.9-.7 3.7-1.9 5.2L553.5 514l130 155c1.2 1.5 1.9 3.3 1.9 5.2 0 4.4-3.6 8-8 8z"></path></svg></i><span>'+msg+'</span></div></div></div></span>');
        }
        else {
            $(document.body).append('<div><div class="ant-message"><span><div class="ant-message-notice"><div class="ant-message-notice-content"><div class="ant-message-custom-content ant-message-error"><i aria-label="icon: close-circle" class="anticon anticon-close-circle"><svg viewBox="64 64 896 896" focusable="false" class="" data-icon="close-circle" width="1em" height="1em" fill="currentColor" aria-hidden="true"><path d="M512 64C264.6 64 64 264.6 64 512s200.6 448 448 448 448-200.6 448-448S759.4 64 512 64zm165.4 618.2l-66-.3L512 563.4l-99.3 118.4-66.1.3c-4.4 0-8-3.5-8-8 0-1.9.7-3.7 1.9-5.2l130.1-155L340.5 359a8.32 8.32 0 0 1-1.9-5.2c0-4.4 3.6-8 8-8l66.1.3L512 464.6l99.3-118.4 66-.3c4.4 0 8 3.5 8 8 0 1.9-.7 3.7-1.9 5.2L553.5 514l130 155c1.2 1.5 1.9 3.3 1.9 5.2 0 4.4-3.6 8-8 8z"></path></svg></i><span>'+msg+'</span></div></div></div></span></div></div>');
        }

        setTimeout(function () {
            quark.hideTip()
        }, timeout || 3000);
    };

    //隐藏
    quark.hideTip = function() {
        $(".ant-message").html('<span></span>');
    };

    //初始化
    quark.install= function () {
        quark.mainList();
        console.log("夸克云盘插件初始化");
        var url = location.href;
        if (url.indexOf(".quark.cn/s/") > 0) {
            //分享页面初始化
            quark.sharePage();
            quark.showTipSuccess("夸克云盘插件初始化成功!");
        }
        else if (url.indexOf(".quark.cn/list") > 0) {
            // debugger
            //主页面初始化
            quark.customSharePwd();
            quark.showTipSuccess("夸克云盘插件初始化成功!");
           // quark.mainPage();
        }

    }();
    // Your code here...
})();