TODO: worker.js 完善接收数据的方案.

This commit is contained in:
eson 2020-11-17 19:54:25 +08:00
parent 9ec4a86611
commit 324322cf23

View File

@ -1,31 +1,33 @@
var href = window.location.href; var href = window.location.href;
var content = document.documentElement.innerHTML; var content = document.documentElement.innerHTML;
var interval = setInterval(function(){ if (href.startsWith("https://playerduo.com") && content.startsWith('<head></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">')) {
GetTask();
}, 6000)
if (href.startsWith("https://playerduo.com")) {
if (content.startsWith('<head></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">')) {
SendContent(); SendContent();
clearInterval(interval); } else {
GetTask(); GetTask()
}
} }
function SendContent() { function SendContent() {
chrome.runtime.sendMessage({ type: BackgroundMsgType.CONTENT, content: content }, chrome.runtime.sendMessage({ type: BackgroundMsgType.CONTENT, content: content },
function (response) { function (response) {
console.log(response.type, response); console.log(response);
GetTask();
}) })
} }
function GetTask() { function GetTask() {
chrome.runtime.sendMessage({ type: BackgroundMsgType.GETTASK }, function (response) { chrome.runtime.sendMessage({ type: BackgroundMsgType.GETTASK }, function (response) {
console.log(response); switch(response.type) {
case BackgroundMsgType.FETCH:
setTimeout(function(){
GetTask();
}, 6000)
case BackgroundMsgType.WAIT:
setTimeout(function(){
GetTask();
}, 1000);
}
}) })
} }