MCPcopy
hub / github.com/xcanwin/KeepChatGPT / hookXHR

Function hookXHR

KeepChatGPT.user.js:2410–2437  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

2408
2409 // 网络层兜底:补充 XHR 拦截,兼容未经过 fetch 的跟踪请求。
2410 const hookXHR = function () {
2411 const XHR = unsafeWindow.XMLHttpRequest;
2412 if (!XHR || !XHR.prototype) return;
2413 if (XHR.prototype._kcgHooked === true) return;
2414 XHR.prototype._kcgHooked = true;
2415 const xhrOpen = XHR.prototype.open;
2416 const xhrSend = XHR.prototype.send;
2417
2418 XHR.prototype.open = function (method, url, ...rest) {
2419 this._kcg_url = typeof url === "string" ? url : `${url || ""}`;
2420 return xhrOpen.call(this, method, url, ...rest);
2421 };
2422
2423 XHR.prototype.send = function (...args) {
2424 try {
2425 const xhrReqUrl = this._kcg_url || "";
2426 if (
2427 gv("k_intercepttracking", false) &&
2428 isTrackingRequest(xhrReqUrl)
2429 ) {
2430 console.log(`KeepChatGPT: ${tl("拦截跟踪")}: ${xhrReqUrl}`);
2431 this.abort();
2432 return;
2433 }
2434 } catch (e) {}
2435 return xhrSend.apply(this, args);
2436 };
2437 };
2438
2439 const everChanging = function (action) {
2440 if (action === true) {

Callers 1

Calls 3

gvFunction · 0.85
isTrackingRequestFunction · 0.85
tlFunction · 0.85

Tested by

no test coverage detected