// // background.js // chrome.runtime.onInstalled.addListener(function () { // console.log("插件已被安装"); // }); // let jsRequests = []; // let jsRequestsByTab = {}; // 用于存储每个标签页的请求 // chrome.webRequest.onBeforeRequest.addListener( // (details) => { // const tabId = details.tabId; // 获取当前请求的标签页 ID // const url = details.url; // let uri = new URL(url); // if ( // details.initiator && // uri.pathname.endsWith(".js") && // (uri.protocol.startsWith("http") || uri.protocol.startsWith("https")) // ) { // // 确保有个数组来记录当前标签页的请求 // if (!jsRequestsByTab[tabId]) { // jsRequestsByTab[tabId] = []; // } // jsRequestsByTab[tabId].push(url); // } // }, // { urls: [""] } // ); // chrome.runtime.onMessage.addListener((request, sender, sendResponse) => { // if (request.action === "getJsRequests") { // const tabId = sender.tab.id; // 获取请求来源的标签页 ID // sendResponse(jsRequestsByTab[tabId] || []); // } // }); // // 监听标签页更新(包括刷新)事件以清空请求记录 // chrome.tabs.onUpdated.addListener((tabId, changeInfo, tab) => { // if (changeInfo.status === "loading") { // // 标签页加载完成时清空请求记录 // delete jsRequestsByTab[tabId]; // } // }); // // 监听标签页关闭事件以清空请求记录 // chrome.tabs.onRemoved.addListener((tabId) => { // delete jsRequestsByTab[tabId]; // 清空对应标签页的请求记录 // });