105 lines
2.3 KiB
JavaScript
105 lines
2.3 KiB
JavaScript
|
|
var task_manager = {
|
|
}
|
|
|
|
function GetTask(sender) {
|
|
fetch(TaskUrl).then(function (response) {
|
|
task_manager[sender.tab.id] = response;
|
|
chrome.tabs.executeScript(sender.tab.id, { "runAt": "document_end", file: "background/task.js" }, function (results) {
|
|
})
|
|
}).catch(function (reason) {
|
|
console.log(reason);
|
|
})
|
|
}
|
|
|
|
chrome.runtime.onMessage.addListener(function (request, sender, sendResponse) {
|
|
switch (request.type) {
|
|
case BackgroundMsgType.CONTENT:
|
|
console.log(request, task_manager, sender); // 利用sender tab id 返回正确的任务id
|
|
case BackgroundMsgType.ERROR:
|
|
console.log(request, task_manager, sender); // 利用sender tab id 返回正确的任务id
|
|
case BackgroundMsgType.GETTASK:
|
|
console.log(request, task_manager, sender); // 利用sender tab id 返回正确的任务id
|
|
}
|
|
// sendResponse({type: MsgType.NEWURL, url: "https://playerduo.com/api/playerDuo-service-v2/rip113?lang=en&deviceType=browser"});
|
|
GetTask(sender);
|
|
sendResponse();
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 配置使用的监听
|
|
chrome.webRequest.onBeforeRequest.addListener(function (details) {
|
|
if (details.url.startsWith("http://eson.config")) {
|
|
var params = new URLSearchParams(details.url)
|
|
TaskUrl = params.get("taskurl");
|
|
chrome.tabs.remove(details.tabId, function () { });
|
|
return { cancel: true };
|
|
}
|
|
}, { 'urls': ["<all_urls>"] }, ['blocking']);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// chrome.webRequest.onCompleted.addListener(
|
|
// function (details) {
|
|
// console.log(details);
|
|
// console.log(document);
|
|
// // return { responseHeaders: details.responseHeaders};
|
|
// },
|
|
// {
|
|
// urls: ["<all_urls>"],
|
|
// types: [
|
|
// "main_frame",
|
|
// "sub_frame",
|
|
// "stylesheet",
|
|
// "script",
|
|
// "image",
|
|
// "object",
|
|
// "xmlhttprequest",
|
|
// "other"
|
|
// ]
|
|
// },
|
|
// ["responseHeaders", "extraHeaders"]
|
|
// );
|
|
|
|
|
|
|
|
// fetch('https://playerduo.com/api/playerDuo-service-v2/rip113?lang=en&deviceType=browser').then(r => r.text()).then(result => {
|
|
// // Result now contains the response text, do what you want...
|
|
// console.log(result);
|
|
// })
|
|
|
|
// chrome.webRequest.onBeforeRequest.addListener(function(data){
|
|
// // data contains request_body
|
|
// return {redirectUrl: "https://playerduo.com/api/playerDuo-service-v2/rip113?lang=en&deviceType=browser"};
|
|
// },{'urls':["<all_urls>"]},['blocking']);
|