95 lines
2.4 KiB
JavaScript
95 lines
2.4 KiB
JavaScript
var href = window.location.href;
|
|
var content = document.documentElement.innerHTML;
|
|
|
|
if (href.startsWith("https://playerduo.com") && content.startsWith('<head></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">')) {
|
|
SendContent();
|
|
} else {
|
|
GetTask()
|
|
}
|
|
|
|
|
|
function SendContent() {
|
|
chrome.runtime.sendMessage({ type: BackgroundMsgType.CONTENT, content: content },
|
|
function (response) {
|
|
console.log(response);
|
|
GetTask();
|
|
})
|
|
}
|
|
|
|
function GetTask() {
|
|
chrome.runtime.sendMessage({ type: BackgroundMsgType.GETTASK }, function (response) {
|
|
switch(response.type) {
|
|
case InjectMsgType.WAIT:
|
|
setTimeout(function(){
|
|
GetTask();
|
|
}, 1000);
|
|
default:
|
|
setTimeout(function(){
|
|
GetTask();
|
|
}, 6000)
|
|
}
|
|
})
|
|
}
|
|
|
|
|
|
|
|
|
|
// var reset = {
|
|
// timeout: setTimeout(function () {
|
|
// chrome.runtime.sendMessage({ type: BackgroundMsgType.TIMEOUT }, function (response) {
|
|
// console.log(response);
|
|
// })
|
|
// GetTask(1000);
|
|
// }, 7000),
|
|
// isCancel: false,
|
|
// }
|
|
|
|
|
|
|
|
// function GetTask(timeout) {
|
|
// chrome.runtime.sendMessage({ type: BackgroundMsgType.GETTASK }, function (response) {
|
|
// console.log("GetTask:", response.type, response);
|
|
// switch (response.type) {
|
|
// case InjectMsgType.WAIT:
|
|
// if (!reset.isCancel) {
|
|
// clearTimeout(reset.timeout);
|
|
// reset.isCancel = true;
|
|
// }
|
|
// setTimeout(function () {
|
|
// GetTask()
|
|
// }, timeout) // 递归获取请求
|
|
// case InjectMsgType.FETCH:
|
|
// }
|
|
// })
|
|
// }
|
|
|
|
// var href = window.location.href;
|
|
// if (href.startsWith("https://playerduo.com")) {
|
|
// var content = document.documentElement.innerHTML;
|
|
// if (content.startsWith('<head></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">')) {
|
|
// chrome.runtime.sendMessage({ type: BackgroundMsgType.CONTENT, content: content },
|
|
// function (response) {
|
|
// console.log(response.type, response);
|
|
// if (response.type === BackgroundMsgType.GETTASK) {
|
|
// GetTask(1000); // 立即获取任务. 如果没有就等待
|
|
// };
|
|
// })
|
|
// }
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// chrome.runtime.onMessage.addListener(function (request) {
|
|
// if (request.type === BackgroundMsgType.CONTENT) {
|
|
|
|
// }
|
|
|
|
// // chrome.runtime.onMessage.removeListener(assignTextToTextareas); //optional
|
|
// });
|
|
|
|
|