refactor(gettask): 1.simple gettask

This commit is contained in:
eson
2020-11-24 15:16:37 +08:00
parent 0ea415ae78
commit 38d369bb58
10 changed files with 173 additions and 155 deletions

View File

@@ -1,62 +1,18 @@
chrome.runtime.onMessage.addListener(function (request) {
switch (request.type) {
case InjectMsgType.WAIT:
setTimeout(function () {
GetTask();
}, 6000);
break;
case InjectMsgType.NOTASK:
setTimeout(function () {
GetTask();
}, 4000);
break;
case InjectMsgType.FETCH:
setTimeout(function () {
GetTask();
}, 6000)
break;
default:
break;
};
});
var href = window.location.href;
var content = document.documentElement.innerHTML;
if (href.startsWith(Host)) {
GetTask();
} else {
var condition = PassContentCondition != undefined ? PassContentCondition : DefaultContentCondition;
if (condition()) {
console.log(condition, PassContentCondition);
Tell(BackgroundMsgType.CONTENT, content);
} else {
console.log(condition, PassContentCondition);
Tell(BackgroundMsgType.NOTWANT, content);
}
}
function Tell(backgroundType, content) {
try {
if (content == undefined) {
chrome.runtime.sendMessage({ type: backgroundType });
} else {
chrome.runtime.sendMessage({ type: backgroundType, content: content });
}
} catch (error) {
console.log(error);
window.location.href = Host;
}
if(href.startsWith(Host)) {
setInterval(function(){
GetTask();
}, 1);
}
function GetTask() {
Tell(BackgroundMsgType.GETTASK);
}
try {
chrome.runtime.sendMessage({ type: BackgroundMsgType.GETTASK }, function(){});
} catch (error) {
console.log(error);
}
};