// ==UserScript== // @name 123网盘无广告下载增强 // @version 0.30 // @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 // @downloadURL none // ==/UserScript== (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; })();