chromeworker/chromeproxy/content/inject.js
2020-11-23 18:50:25 +08:00

60 lines
1.1 KiB
JavaScript

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;
var condition = PassContentCondition != undefined ? PassContentCondition : DefaultContentCondition;
if (condition()) {
Tell(BackgroundMsgType.CONTENT, content);
} else {
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;
}
}
function GetTask() {
Tell(BackgroundMsgType.GETTASK);
}