chromeworker/chromeproxy/content/inject.js

60 lines
1.1 KiB
JavaScript
Raw Normal View History

2020-11-18 11:49:46 +00:00
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;
};
2020-11-18 11:49:46 +00:00
});
2020-11-23 10:50:25 +00:00
// 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);
2020-11-16 11:04:53 +00:00
}
2020-11-18 11:49:46 +00:00
function Tell(backgroundType, content) {
2020-11-23 10:50:25 +00:00
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;
2020-11-18 11:49:46 +00:00
}
2020-11-23 10:50:25 +00:00
}
function GetTask() {
2020-11-18 11:49:46 +00:00
Tell(BackgroundMsgType.GETTASK);
}
2020-11-16 11:04:53 +00:00