123网盘无广告下载增强

123网盘去广告,并伪装客户端下载

目前为 2025-01-01 提交的版本。查看 最新版本

// ==UserScript==
// @name         123网盘无广告下载增强
// @version      0.31
// @description  123网盘去广告,并伪装客户端下载
// @author       HSSkyBoy
// @match        https://www.123pan.com/s/*
// @match        https://www.123pan.cn/s/*
// @match        https://www.123912.com/*
// @match        https://www.123865.com/*
// @namespace       https://www.123pan.cn/
// @license MIT
// @grant        none
// ==/UserScript==

document.addEventListener('copy', function(e) {
    // 阻止默认行为
    e.preventDefault();
    // 阻止事件传播
    e.stopPropagation();
});

function addStyle(cssstyle) {
    let styleNode = document.createElement("style");
    styleNode.appendChild(document.createTextNode(cssstyle));
    (document.querySelector("head") || document.documentElement).appendChild(styleNode);
}

// 添加样式
let css = `
.appBottomBtn {
    position: fixed !important;
    bottom: 0 !important; 
}

#xxl {
    position: fixed !important;
    top: 1% !important;
    right: 1% !important;
    width: 98% !important;
}

.banner_all_wrap, .pointer, .qrcode_btn, share-time-wrap__operate, img[src="https://statics.123pan.com/share-static/dist/static/H5_logo_top.2b680600.svg"], .loginModal-footer, .download-msg-info, nner-container-h5, .app-header-img, .bg_svip_block_ads, .sharheader_left {
   display: none !important; 
}
`;

addStyle(css);

setTimeout(function() {
    var pageTitle = document.title;
    var index = pageTitle.indexOf("官方版下载丨");
    if (index !== -1) {
        var newTitle = pageTitle.substring(0, index);
        document.title = newTitle;
    }
}, 1000);

// 修改页面中的特定文本
function modifyText() {
    const allElements = document.getElementsByTagName('*');
    for (let i = 0; i < allElements.length; i++) {
        const element = allElements[i];
        if (element.textContent && element.textContent.includes('永久分享')) {
            element.textContent = element.textContent.replace('永久分享', '10年后过期');
        }
    }
}

// 修改文本
modifyText();

(function () {
    // 配置对象,包含请求头和日志记录开关
    const config = {
        headers: {
            "user-agent": "123pan/v2.4.10(Android_12;Huawei)",
            "platform": "android",
            "app-version": "72",
            "x-app-version": "2.4.10"
        },
        logEnabled: true // 控制日志记录的开关
    };

    // 重写 XMLHttpRequest
    const originalXHR = window.XMLHttpRequest;

    function newXHR() {
        const realXHR = new originalXHR();

        // 重写 open 方法,记录请求的 URL
        realXHR.open = function (method, url, async, user, password) {
            this._url = url;  // 记录请求的 URL
            return originalXHR.prototype.open.apply(this, arguments);
        };

        // 重写 setRequestHeader 方法,修改特定的请求头
        realXHR.setRequestHeader = function (header, value) {
            // 如果 header 在配置中,则使用配置中的值
            if (header.toLowerCase() in config.headers) {
                value = config.headers[header.toLowerCase()];
            }
            if (config.logEnabled) {
                console.log('Setting header:', header, 'to', value);
            }
            return originalXHR.prototype.setRequestHeader.apply(this, arguments);
        };

        // 重写 send 方法,拦截响应内容,修改 DownloadUrl
        realXHR.send = function () {
            const xhrInstance = this;
            this.addEventListener('readystatechange', function () {
                if (xhrInstance.readyState === 4) {
                    if (xhrInstance.status === 200) {
                        // 解析响应的 JSON
                        let responseText = xhrInstance.responseText;
                        let responseJSON;
                        try {
                            responseJSON = JSON.parse(responseText);
                        } catch (e) {
                            if (config.logEnabled) {
                                console.error('Error parsing JSON response:', e);
                            }
                            return;
                        }

                        if (config.logEnabled) {
                            console.log('Original Response:', responseJSON);
                        }

                        // 修改 DownloadUrl
                        if (responseJSON.data && responseJSON.data.DownloadUrl) {
                            let origin_url = responseJSON.data.DownloadUrl;
                            let new_url_no_redirect = origin_url + "&auto_redirect=0";
                            let base64data = btoa(new_url_no_redirect);
                            responseJSON.data.DownloadUrl = "https://web-pro2.123952.com/download-v2/?params=" + base64data + "&is_s3=0";
                            if (config.logEnabled) {
                                console.log('Modified DownloadUrl:', responseJSON.data.DownloadUrl);
                            }
                        }

                        // 将修改后的 JSON 转为字符串
                        let modifiedResponseText = JSON.stringify(responseJSON);

                        // 使用 defineProperty 重写 responseText
                        Object.defineProperty(xhrInstance, 'responseText', {
                            get: function () {
                                return modifiedResponseText;
                            }
                        });
                        if (config.logEnabled) {
                            console.log('Modified Response:', modifiedResponseText);
                        }
                    } else {
                        if (config.logEnabled) {
                            console.error('Request failed with status:', xhrInstance.status);
                        }
                    }
                }
            });

            return originalXHR.prototype.send.apply(this, arguments);
        };

        return realXHR;
    }

    window.XMLHttpRequest = newXHR;
})();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址