TODO: worker.js 完善接收数据的方案.
This commit is contained in:
parent
9ec4a86611
commit
324322cf23
|
@ -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();
|
SendContent();
|
||||||
}, 6000)
|
} else {
|
||||||
|
GetTask()
|
||||||
if (href.startsWith("https://playerduo.com")) {
|
|
||||||
if (content.startsWith('<head></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">')) {
|
|
||||||
SendContent();
|
|
||||||
clearInterval(interval);
|
|
||||||
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);
|
||||||
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user