chromeworker/myblock/content/inject.js
2020-11-16 19:04:53 +08:00

58 lines
1.2 KiB
JavaScript

function Execute(response) {
window.location.href = response.url;
window.location.hash = response.tid
}
function TimeoutClient(tm) {
setTimeout(function () {
chrome.runtime.sendMessage({ type: MsgType.TIMEOUT }, function (response) {
switch (response.type) {
case MsgType.NEWURL:
Execute(response)
case MsgType.WAIT:
TimeoutClient(1000);
}
});
}, tm);
}
var tm = 6000;
try {
var href = window.location.href;
var tid = window.location.hash;
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: MsgType.CONTENT,
tid: tid,
content: content,
},
function (response) {
console.log(response.type, response);
switch (response.type) {
case MsgType.NEWURL:
Execute(response);
case MsgType.WAIT:
tm = 1000;
default:
}
}
);
}
}
} catch (error) {
chrome.runtime.sendMessage({type: MsgType.ERROR, msg: error})
} finally {
TimeoutClient(tm);
}