feat(config): add retry and waitcapture property
This commit is contained in:
@@ -2,30 +2,22 @@ var href = window.location.href;
|
||||
var content = document.documentElement.innerHTML;
|
||||
|
||||
try {
|
||||
if(waittime === undefined) {
|
||||
waittime = 6000
|
||||
if (condition == undefined) {
|
||||
condition = function () {
|
||||
return true;
|
||||
};
|
||||
}
|
||||
} catch (error) {
|
||||
waittime = 6000
|
||||
}
|
||||
|
||||
|
||||
if (condition == undefined) {
|
||||
condition = function () {
|
||||
return true;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
if (condition()) {
|
||||
Tell(BackgroundMsgType.CONTENT, content);
|
||||
} else {
|
||||
setTimeout(function () {
|
||||
if (condition()) {
|
||||
Tell(BackgroundMsgType.CONTENT, content);
|
||||
} else {
|
||||
Tell(BackgroundMsgType.NOTWANT, content);
|
||||
}
|
||||
}, waittime)
|
||||
Tell(BackgroundMsgType.NOTWANT, content);
|
||||
}
|
||||
|
||||
function Tell(backgroundType, content) {
|
||||
|
||||
@@ -16,16 +16,29 @@ chrome.runtime.onMessage.addListener(function (request, sender, sendResponse) {
|
||||
GetTask(sender);
|
||||
break;
|
||||
case BackgroundMsgType.NOTWANT:
|
||||
|
||||
task = task_manager[sender.tab.id];
|
||||
task.data.retry --;
|
||||
if(task.data.retry >= 0) {
|
||||
CaptureContent(task);
|
||||
} else {
|
||||
ErrorTask(sender, request.content);
|
||||
}
|
||||
|
||||
if(task.data.waitcapture != undefined) {
|
||||
setTimeout(function(){
|
||||
CaptureContentCurrentPage(sender.tab.id);
|
||||
}, task.data.waitcapture);
|
||||
} else {
|
||||
|
||||
task.data.retry --;
|
||||
if(task.data.retry >= 0) {
|
||||
setTimeout(function(){
|
||||
CaptureContent(task);
|
||||
}, 6000)
|
||||
} else {
|
||||
ErrorTask(sender, request.content);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
break;
|
||||
case BackgroundMsgType.CLOSETAB:
|
||||
delete task_manager[sender.tab.id]
|
||||
chrome.tabs.remove(sender.tab.id);
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@@ -48,6 +61,10 @@ function GetTask(sender) {
|
||||
})
|
||||
}
|
||||
|
||||
function CaptureContentCurrentPage(tabid) {
|
||||
chrome.tabs.executeScript(tabid, { runAt: "document_end", file: "background/capture.js" });
|
||||
}
|
||||
|
||||
function CaptureContent(task) {
|
||||
if (task.code == 200) {
|
||||
|
||||
@@ -60,12 +77,12 @@ function CaptureContent(task) {
|
||||
if (task.data.content_condition) {
|
||||
condition = `${task.data.content_condition}`
|
||||
}
|
||||
if (condition) {
|
||||
if (condition != undefined) {
|
||||
chrome.tabs.executeScript(tab.id, { runAt: "document_end", code: condition }, function () {
|
||||
chrome.tabs.executeScript(tab.id, { runAt: "document_end", file: "background/capture.js" });
|
||||
CaptureContentCurrentPage(tab.id)
|
||||
});
|
||||
} else {
|
||||
chrome.tabs.executeScript(tab.id, { runAt: "document_end", file: "background/capture.js" });
|
||||
CaptureContentCurrentPage(tab.id)
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -74,7 +91,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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user