您需要先安装一个扩展,例如 篡改猴、Greasemonkey 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 Userscripts ,之后才能安装此脚本。
您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。
您需要先安装用户脚本管理器扩展后才能安装此脚本。
拦截并处理HTTP请求
// ==UserScript== // @name 拦截XHR请求 // @namespace http://tampermonkey.net/ // @version 1.0 // @description 拦截并处理HTTP请求 // @author czy // @match *://console.huaweicloud.com/cse2/* // @license MIT // @run-at document-start // @require https://unpkg.com/ajax-hook/dist/ajaxhook.min.js // @grant none // ==/UserScript== (function() { 'use strict'; var XHR = XMLHttpRequest.prototype; var open = XHR.open; var send = XHR.send; XHR.open = function (method, url) { this._method = method; this._url = url; if (url.includes("&limit=50") && method.includes("GET") ) { url = url.substring(0, url.length - 9); this._changeUrl = true; } console.log('xhr request:', this._method, this._url, url, this._changeUrl); if (this._changeUrl) { return open.call(this, method, url, arguments); } else { return open.apply(this, arguments); } }; XHR.send = function (postData) { console.log('xhr request:', this._method, this._url, postData); return send.apply(this, arguments); }; const originalXHR = window.XMLHttpRequest; // 重写XMLHttpRequest构造函数 window.XMLHttpRequest = function() { var xhr = new originalXHR(); // 监听响应完成事件 xhr.addEventListener('load', function() { console.log('xhr responseText:', this._url, this.responseText); }); return xhr; }; })();