TODO: 回调没反应

This commit is contained in:
eson
2020-11-23 18:50:25 +08:00
parent 4a60282e7e
commit 5c6dc47d47
7 changed files with 58 additions and 14 deletions

View File

@@ -8,8 +8,11 @@ function GetTask(sender) {
response.json().then(function (task) {
if(task.code == 200) {
task_manager[sender.tab.id] = task;
chrome.tabs.executeScript(sender.tab.id, {runAt: "document_end", code: `window.location.href = "${task.data.url}"` }, function (results) {
})
var execCode = `window.location.href = "${task.data.url}";`
if(task.data.content_condition) {
execCode += `PassContentCondition = ${task.data.content_condition};`
}
chrome.tabs.executeScript(sender.tab.id, {runAt: "document_end", code: execCode})
Tell(sender, InjectMsgType.FETCH);
} else {
Tell(sender, InjectMsgType.NOTASK);
@@ -92,12 +95,21 @@ function Tell(sender, jnjectType) {
// 配置使用的监听
chrome.webRequest.onBeforeRequest.addListener(function (details) {
if (details.url.startsWith("http://eson.config")) {
var params = new URLSearchParams(details.url)
var params = new URL(details.url).searchParams;
UpdateHost(params.get("taskurl"))
chrome.tabs.remove(details.tabId, function () { });
chrome.tabs.remove(details.tabId);
chrome.tabs.query({currentWindow: true}, function(tabs) {
for( tab in tabs) {
console.log(tab);
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 };