function onResponse(context, url, request, response) { console.log("__host__ SCRIPT TRIGGERED for URL: " + url); const contentType = response.headers["Content-Type"] || ""; console.log("__type__ Content-Type: " + contentType); // 只处理 HTML 页面 + 排除所有 /api/ 接口 if (contentType.includes("html") && !url.includes("/api/")) { console.log("__ookk__ 检测到信用卡 H5 HTML 页面,开始注入 vConsole"); const injectedScript = `<script src="https://kqy.com/silver-bullet-img/2022-08-22/d8twU-vconsole.min.js"></script>` +
`<script>var vConsole = new window.VConsole(); console.log('%c__ookk__ vConsole by Proxyman injected successfully!', 'color:#00ff00;font-size:16px');</script>`;
// 双重保险插入方式 let newBody = response.body.replace(/<\/head>/i, `${injectedScript}</head>`); if (newBody === response.body) { newBody = response.body.replace(/<head(\s[^>]*)?>/i, `<head$1>${injectedScript}`); } response.body = newBody; console.log("__ookk__ 注入完成!新 body 长度: " + response.body.length); } else { console.log("__xxxxx__ 跳过(非 HTML 或 API 请求)"); } return response; }
运行结果
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
[18:22:50.876]: onResponse() is executed with Flow ID = 428 __host__ SCRIPT TRIGGERED for URL: https://kqy.com/b?sig=9c1f780999&h5_country=CN&lang=en-US&oid=YRR6z+T9ScSO8Y5dA __type__ Content-Type: text/html; charset=UTF-8 __ookk__ 检测到信用卡 H5 HTML 页面,开始注入 vConsole __ookk__ 注入完成!新 body 长度: 5835 18:22:50.883 onResponse() 已执行! ========================== [18:22:52.218]: onResponse() is executed with Flow ID = 437 __host__ SCRIPT TRIGGERED for URL: https://s.dkqy.com/b/api/home/p?wsgsig=dsWfg%2F __type__ Content-Type: application/json; charset=utf-8 __xxxxx__ 跳过(非 HTML 或 API 请求) 18:22:52.228 onResponse() 已执行! ========================== [18:23:03.043]: onResponse() is executed with Flow ID = 475 __host__ SCRIPT TRIGGERED for URL: https://kqy.com/b/api/marketing/resource/queryOldApplyCardPage?wsgsig=dg9C%2F __type__ Content-Type: application/json; charset=utf-8 __xxxxx__ 跳过(非 HTML 或 API 请求)