您需要先安装一个扩展,例如 篡改猴、Greasemonkey 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 Userscripts ,之后才能安装此脚本。
您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。
您需要先安装用户脚本管理器扩展后才能安装此脚本。
XHR请求拦截工具类
当前为
此脚本不应直接安装。它是供其他脚本使用的外部库,要使用该库请加入元指令 // @require https://update.cn-greasyfork.org/scripts/494576/1374297/XHR_Interceptor.js
// ==UserScript== // @name XHR_Interceptor // @version 1.0.0 // @description XHR请求拦截工具类 // @author Zosah // ==/UserScript== class XMRHandler { constructor() { if (XMRHandler.instance) { return XMRHandler.instance; } this.interceptors = []; XMRHandler.instance = this; } addUrlInterceptor(item) { this.interceptors.push(item); } execute() { function xhrInterceptor(callback) { // send拦截 let oldSend = null; // 在xhr函数下创建一个回调 XMLHttpRequest.callbacks = function (xhr) { //调用劫持函数,填入一个function的回调函数 //回调函数监听了对xhr调用了监听load状态,并且在触发的时候再次调用一个function,进行一些数据的劫持以及修改 xhr.addEventListener("load", function () { if (xhr.readyState == 4 && xhr.status == 200) { callback(xhr); } }); }; //获取xhr的send函数,并对其进行劫持 oldSend = XMLHttpRequest.prototype.send; XMLHttpRequest.prototype.send = function () { XMLHttpRequest.callbacks(this); //由于我们获取了send函数的引用,并且复写了send函数,这样我们在调用原send的函数的时候,需要对其传入引用,而arguments是传入的参数 oldSend.apply(this, arguments); }; } xhrInterceptor((xhr) => { for (const item of this.interceptors) { const url = xhr.responseURL.split(item.domain)[1]; if (url === item.url) { item.cb(JSON.parse(xhr.response)); } } }); } }