// ==UserScript== // @name 请求拦截并显示返回数据 // @namespace // @version 2024-02-21 // @description 请求显示方法、地址、数据 // @author ghost // @match http://*/* // @icon // @grant none // @downloadURL 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; return open.apply(this, arguments); }; XHR.send = function (postData) { this.addEventListener('load', function () { //window.postMessage({ type: 'xhr', data: this.response }, '*'); // 将响应发送到 content script console.log('request:', this._method, this._url, postData); console.log(JSON.parse(this.response)) }); return send.apply(this, arguments); }; })();