// ==UserScript== // @name 智谱GLM-Coding plan 抢购 // @namespace http://tampermonkey.net/ // @version 2.0 // @description 修改前端,让抢购按钮不需要在规定时间才可以点击,比别人更快一步进入付款界面 // @author hesheng4869 // @match *://www.bigmodel.cn/* // @match *://www.bigmodel.cn/glm-coding // @match *://bigmodel.cn/glm-coding* // @match *://*.bigmodel.cn/glm-coding* // @run-at document-start // @grant none // @license MIT // @downloadURL https://update.greasyfork.icu/scripts/575588/%E6%99%BA%E8%B0%B1GLM-Coding%20plan%20%E6%8A%A2%E8%B4%AD.user.js // @updateURL https://update.greasyfork.icu/scripts/575588/%E6%99%BA%E8%B0%B1GLM-Coding%20plan%20%E6%8A%A2%E8%B4%AD.meta.js // ==/UserScript== (function() { 'use strict'; const SCRIPT_NAME = '[抢购助手1.0]'; const STOCK_VALUE = 999; console.log(`${SCRIPT_NAME} 拦截器已启动...`); function isProductObject(obj) { return obj.price !== undefined || obj.productId !== undefined || obj.title !== undefined; } function deepModify(obj) { if (!obj || typeof obj !== 'object') return; // 篡改核心售罄标识 if (obj.isSoldOut === true) { obj.isSoldOut = false; } if (obj.soldOut === true) { obj.soldOut = false; } // 如果遇到 disabled,且该对象看起来是个商品,则强制启用 if (obj.disabled === true && isProductObject(obj)) { obj.disabled = false; } // 修改库存数量 if (obj.stock === 0) { obj.stock = STOCK_VALUE; } // 递归处理 for (const key in obj) { if (obj[key] && typeof obj[key] === 'object') { deepModify(obj[key]); } } } function modifyResponseText(text) { return text .replace(/"isSoldOut":true/g, '"isSoldOut":false') .replace(/"disabled":true/g, '"disabled":false') .replace(/"soldOut":true/g, '"soldOut":false') .replace(/"stock":0/g, `"stock":${STOCK_VALUE}`); } function hasSoldOutStatus(text) { return text.includes('"isSoldOut":true') || text.includes('"disabled":true') || text.includes('"soldOut":true'); } // ========================================== // 战术一:拦截 SSR 页面初始注入数据 // 通过劫持浏览器的 JSON 解析器,修改带有"售罄"属性的对象 // ========================================== const originalJSONParse = JSON.parse; JSON.parse = function(text, reviver) { const result = originalJSONParse(text, reviver); try { deepModify(result); } catch (error) { } return result; }; // ========================================== // 战术二:拦截 Fetch 接口请求 // 针对用户在页面停留时,前端向后端发起的库存/价格检查 // ========================================== const originalFetch = window.fetch; window.fetch = async function(...args) { const response = await originalFetch.apply(this, args); const contentType = response.headers.get('content-type') || ''; if (!contentType.includes('application/json')) { return response; } const clone = response.clone(); try { let text = await clone.text(); if (hasSoldOutStatus(text)) { console.log(`${SCRIPT_NAME} 拦截到 Fetch 售罄数据,正在执行篡改!`, args[0]); text = modifyResponseText(text); return new Response(text, { status: response.status, statusText: response.statusText, headers: response.headers }); } } catch (error) { } return response; }; // ========================================== // 战术三:拦截 XMLHttpRequest (兜底方案) // ========================================== const originalXHROpen = XMLHttpRequest.prototype.open; const originalXHRSend = XMLHttpRequest.prototype.send; XMLHttpRequest.prototype.open = function(method, url, ...rest) { this._requestUrl = url; return originalXHROpen.call(this, method, url, ...rest); }; XMLHttpRequest.prototype.send = function(...args) { this.addEventListener('readystatechange', function() { if (this.readyState !== 4 || this.status !== 200) { return; } const contentType = this.getResponseHeader('content-type') || ''; if (!contentType.includes('application/json')) { return; } try { let text = this.responseText; if (hasSoldOutStatus(text)) { console.log(`${SCRIPT_NAME} 拦截到 XHR 售罄数据,正在执行篡改!`, this._requestUrl); text = modifyResponseText(text); Object.defineProperty(this, 'responseText', { get: function() { return text; } }); Object.defineProperty(this, 'response', { get: function() { return JSON.parse(text); } }); } } catch (error) { } }); originalXHRSend.apply(this, args); }; })();