- SignalDesk2 hr ago
Original Summary
(() => { // 避免重复安装 if (window.__promoCampaignFetchHook) { console.warn("[fetch hook] 已经安装,无需重复执行。"); return; } const originalFetch = window.fetch; /** 尝试删除 JSON 文本中的顶层 promo_campaign 字段。 / function removePromoCampaign(bodyText) { if (typeof bodyText !== "string" || !bodyText.trim()) { return null; } try { const data = JSON.parse(bodyText); if ( data === null || typeof data !== "object" || Array.isArray(data) || !Object.prototype.hasOwnProperty.call(data, "promo_campaign") ) { return null; } const removedValue = data.promo_campaign; delete data.promo_campaign; return { body: JSON.stringify(data), removedValue, data, }; } catch { // 不是合法 JSON,不处理 return null; } } window.fetch = async function hookedFetch(input, init) { let requestUrl = typeof input === "string" ? input : input instanceof URL ? input.href : input?.url; / 情况一: fetch(url, { body: JSON.stringify(...) }) 或 fetch(request, { body: ... }) / if (init && typeof init.body === "string") { const result = removePromoCampaign(init.body); if (result) { init = { ...init, body: result.body, }; console.log("[fetch hook] 已删除 promo_campaign", { url: requestUrl, removedValue: result.removedValue, modifiedBody: result.data, }); } return originalFetch.call(this, input, init); } / 情况二: fetch(new Request(url, { body: JSON.stringify(...) })) */ if ( input instanceof Request && !input.bodyUsed && !["GET", "HEAD"].includes(input.method.toUpperCase()) ) { try { const bodyText = await input.clone().text(); const result = removePromoCampaign(bodyText); if (result) { const modifiedRequest = new Request(input, { body: result.body, }); console.log("[fetch hook] 已删除 promo_campaign", { url: input.url, removedValue: result.removedValue, modifiedBody: result.data, }); return originalFetch.call(this, modifiedRequest, init); } } catch (error) { console.warn("[fetch hook] 检查 Request 请求体失败,已使用原请求:", error); } } return originalFetch.call(this, input, init); }; window.__promoCampaignFetchHook = { uninstall() { window.fetch = originalFetch; delete window.__promoCampaignFetchHook; console.log("[fetch hook] 已卸载。"); }, }; console.log( "[fetch hook] 安装成功。卸载请执行:window.__promoCampaignFetchHook.uninstall()" ); })(); 1 个帖子 - 1 位参与者 阅读完整话题
- 情报分类:商业与市场研究
- 分类依据:内容涉及商业、投资或市场动态
- 信息来源:服务器 / LINUX DO - 最新话题
- 发布时间:2026/10/20 15:54:39
- No replies yet