// ==UserScript== // @name 123云盘下载辅助 // @namespace https://github.com/Holmes/123pan // @version 1 // @description 123 Cloud Drive Unlimited Flow // @match https://www.123pan.com/* // @match https://www.123pan.cn/* // @match https://www.123865.com/* // @match https://www.123684.com/* // @grant none // @author Holmes // ==/UserScript== (function () { // Save the original XMLHttpRequest object for later use const originalXHR = window.XMLHttpRequest; // Function to create a new XMLHttpRequest with modified behavior function newXHR() { const realXHR = new originalXHR(); // Override the open method to capture the request URL realXHR.open = function (method, url, async, user, password) { this._url = url; // Store the URL of the request return originalXHR.prototype.open.apply(this, arguments); }; // Override the setRequestHeader method to modify specific headers realXHR.setRequestHeader = function (header, value) { // Define headers to be modified and their replacement values let headers = { "user-agent": "123pan/v2.4.0(Android_7.1.2;Xiaomi)", // Set user agent to mimic Android app //"loginuuid": generateUUIDHex(), "platform": "android", // Set platform to Android "app-version": "61", // Set app version "x-app-version": "2.4.0" // Additional app version header }; // Check if the header is in the list, and if so, replace its value if (header.toLowerCase() in headers) { value = headers[header.toLowerCase()]; } else { console.log('header:', header); // Log non-modified headers for debugging } // Call the original setRequestHeader method with modified or original value return originalXHR.prototype.setRequestHeader.apply(this, arguments); }; // Override the send method to modify the response data if necessary realXHR.send = function () { const xhrInstance = this; this.addEventListener('readystatechange', function () { let origin_url; let new_url_no_redirect; let base64data; // Check if request is complete and successful if (xhrInstance.readyState === 4 && xhrInstance.status === 200) { // Parse the JSON response let responseText = xhrInstance.responseText; let responseJSON = JSON.parse(responseText); console.log('Original Response:', responseJSON); // Modify the DownloadUrl to prevent auto-redirect and enable web download if (responseJSON.data && responseJSON.data.DownloadUrl) { origin_url = responseJSON.data.DownloadUrl; // Append auto_redirect=0 to disable automatic redirects new_url_no_redirect = origin_url + "&auto_redirect=0"; // Encode the new URL in Base64 format base64data = btoa(new_url_no_redirect); // Set the modified DownloadUrl to point to a server endpoint responseJSON.data.DownloadUrl = "https://web-pro2.123952.com/download-v2/?params=" + base64data + "&is_s3=0"; console.log('Modified DownloadUrl:', responseJSON.data.DownloadUrl); } // Convert modified JSON back to string format let modifiedResponseText = JSON.stringify(responseJSON); // Override the responseText property to return the modified response Object.defineProperty(xhrInstance, 'responseText', { get: function () { return modifiedResponseText; } }); console.log('Modified Response:', modifiedResponseText); } }); // Call the original send method return originalXHR.prototype.send.apply(this, arguments); }; // Return the modified XMLHttpRequest return realXHR; } // Replace the global XMLHttpRequest with the modified version window.XMLHttpRequest = newXHR; })();