fix(closetab): 1.fix close tab. 2.waittime default = 6000

This commit is contained in:
eson 2020-11-25 12:23:46 +08:00
parent 7b5c3717ba
commit 899f554336
4 changed files with 36 additions and 6 deletions

View File

@ -14,6 +14,7 @@
"--ignore-certificate-errors",
"--disable-dev-shm-usage",
"--mute-audio",
"--single-process",
"--safebrowsing-disable-auto-update",
"--disable-gpu",
"--no-sandbox",

View File

@ -1,10 +1,14 @@
var href = window.location.href;
var content = document.documentElement.innerHTML;
setTimeout(function(){
window.close();
}, 15000)
try {
if(waittime === undefined) {
waittime = 6000
}
} catch (error) {
waittime = 6000
}
if (condition == undefined) {
condition = function () {
@ -15,7 +19,13 @@ if (condition == undefined) {
if (condition()) {
Tell(BackgroundMsgType.CONTENT, content);
} else {
Tell(BackgroundMsgType.NOTWANT, content);
setTimeout(function () {
if (condition()) {
Tell(BackgroundMsgType.CONTENT, content);
} else {
Tell(BackgroundMsgType.NOTWANT, content);
}
}, waittime)
}
function Tell(backgroundType, content) {

View File

@ -16,7 +16,15 @@ chrome.runtime.onMessage.addListener(function (request, sender, sendResponse) {
GetTask(sender);
break;
case BackgroundMsgType.NOTWANT:
ErrorTask(sender, request.content);
task = task_manager[sender.tab.id];
task.data.retry --;
if(task.data.retry >= 0) {
CaptureContent(task);
} else {
ErrorTask(sender, request.content);
}
break;
default:
break;
@ -27,6 +35,7 @@ function GetTask(sender) {
fetch(GetTaskUrl).then(function (response) {
if (response.ok) {
response.json().then(function (task) {
CaptureContent(task);
})
} else {
@ -41,6 +50,11 @@ function GetTask(sender) {
function CaptureContent(task) {
if (task.code == 200) {
if(task.data.retry == undefined) {
task.data.retry = 1;
}
chrome.tabs.create({ url: task.data.url }, function (tab) {
task_manager[tab.id] = task;
if (task.data.content_condition) {
@ -60,6 +74,7 @@ function CaptureContent(task) {
function FinishTask(sender, content) {
var task = task_manager[sender.tab.id];
var formdata = new FormData();
formdata.append("taskid", task.data.taskid);
formdata.append("content", content);

View File

@ -3,6 +3,10 @@ if(href.startsWith(Host)) {
setInterval(function(){
GetTask();
}, 1);
} else {
setTimeout(function(){
close();
}, 15000)
}
function GetTask() {