chromeworker/chromeproxy/background/config.js

23 lines
877 B
JavaScript
Raw Normal View History

2020-11-24 07:16:37 +00:00
// 配置使用的监听
chrome.webRequest.onBeforeRequest.addListener(function (details) {
if (details.url.startsWith("http://eson.config")) {
var params = new URL(details.url).searchParams;
UpdateHost(params.get("taskurl"))
chrome.tabs.remove(details.tabId);
chrome.tabs.query({ currentWindow: true }, function (tabs) {
var count = 0
for (var tab of tabs) {
if (!tab.url.startsWith("chrome://")) {
count++;
chrome.tabs.executeScript(tab.id, { runAt: "document_end", code: `window.location.href = "${Host}"` })
} else {
chrome.tabs.remove(tab.id);
}
}
for (var i = count; i < WorkerNumber; i++) {
chrome.tabs.create({ url: `${Host}` });
}
})
return { cancel: true };
}
}, { 'urls': ["<all_urls>"] }, ['blocking']);