2024-05-16 21:27:50 +00:00
|
|
|
(async () => {
|
2024-04-30 18:23:08 +00:00
|
|
|
window.psshs=[];
|
|
|
|
window.requests=[];
|
|
|
|
window.bodys=[];
|
2024-06-11 23:23:29 +00:00
|
|
|
window.targetIds=[];
|
2024-04-30 18:23:08 +00:00
|
|
|
window.pageURL="";
|
2024-05-07 19:43:06 +00:00
|
|
|
window.clearkey="";
|
2024-05-12 01:16:58 +00:00
|
|
|
|
|
|
|
chrome.storage.local.get("isBlock", (value) => {
|
2024-06-21 09:50:42 +00:00
|
|
|
window.isBlock = value.isBlock;
|
2024-05-12 01:16:58 +00:00
|
|
|
})
|
|
|
|
|
2024-04-08 22:58:09 +00:00
|
|
|
function convertHeaders(obj){
|
2024-04-18 20:48:32 +00:00
|
|
|
return JSON.stringify(Object.fromEntries(obj.map(header => [header.name, header.value])))
|
2024-04-08 22:58:09 +00:00
|
|
|
}
|
2024-04-26 01:53:24 +00:00
|
|
|
|
2024-05-16 21:27:50 +00:00
|
|
|
window.blockRules = await fetch("blockRules.conf").then((r)=>r.text());
|
2024-06-25 01:43:09 +00:00
|
|
|
window.blockRules = window.blockRules.replace(/\n^\s*$|\s*\/\/.*|\s*$/gm, "").split("\n");
|
2024-05-16 21:27:50 +00:00
|
|
|
function testBlock(url) {
|
2024-06-25 01:43:09 +00:00
|
|
|
return window.isBlock && window.blockRules.some(e => url.includes(e));
|
2024-05-16 21:27:50 +00:00
|
|
|
}
|
|
|
|
|
2024-04-26 01:53:24 +00:00
|
|
|
//Get URL and headers from POST requests
|
2024-04-08 22:58:09 +00:00
|
|
|
chrome.webRequest.onBeforeSendHeaders.addListener(
|
2024-05-12 01:16:58 +00:00
|
|
|
function(details) {
|
|
|
|
if (details.method === "POST") {
|
|
|
|
window.requests.push({
|
|
|
|
url:details.url,
|
|
|
|
headers:convertHeaders(details.requestHeaders),
|
|
|
|
body:window.bodys.find((b) => b.id == details.requestId).body
|
|
|
|
});
|
2024-05-16 21:27:50 +00:00
|
|
|
if(testBlock(details.url)){
|
2024-05-12 01:16:58 +00:00
|
|
|
return {cancel:true}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{urls: ["<all_urls>"]},
|
|
|
|
["requestHeaders", "blocking"]
|
2024-04-08 22:58:09 +00:00
|
|
|
);
|
|
|
|
|
2024-09-27 05:36:08 +00:00
|
|
|
//Get requestBody from POST requests
|
2024-04-26 01:53:24 +00:00
|
|
|
chrome.webRequest.onBeforeRequest.addListener(
|
2024-06-25 02:11:08 +00:00
|
|
|
function(details) {
|
|
|
|
if (details.method === "POST") {
|
|
|
|
window.bodys.push({
|
2024-09-27 05:36:08 +00:00
|
|
|
body:details.requestBody.raw ? btoa(String.fromCharCode(...new Uint8Array(details.requestBody.raw[0]['bytes']))) : "",
|
|
|
|
id:details.requestId
|
2024-06-25 02:11:08 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{urls: ["<all_urls>"]},
|
|
|
|
["requestBody"]
|
2024-04-26 01:53:24 +00:00
|
|
|
);
|
|
|
|
|
2024-04-08 22:58:09 +00:00
|
|
|
//Receive PSSH from content.js
|
|
|
|
chrome.runtime.onMessage.addListener(
|
2024-06-25 02:11:08 +00:00
|
|
|
function (request, sender, sendResponse) {
|
|
|
|
switch(request.type){
|
|
|
|
case "RESET":
|
|
|
|
location.reload()
|
|
|
|
break;
|
|
|
|
case "PSSH":
|
|
|
|
window.psshs.push(request.text)
|
|
|
|
window.pageURL=sender.tab.url
|
|
|
|
window.targetIds=[sender.tab.id, sender.frameId]
|
|
|
|
break;
|
|
|
|
case "CLEARKEY":
|
|
|
|
window.clearkey=request.text
|
|
|
|
break;
|
|
|
|
}
|
2024-04-08 22:58:09 +00:00
|
|
|
}
|
|
|
|
);
|
2024-05-16 21:27:50 +00:00
|
|
|
} )()
|
2024-04-08 22:58:09 +00:00
|
|
|
|
2024-09-08 15:43:15 +00:00
|
|
|
chrome.browserAction.onClicked.addListener(tab => {
|
|
|
|
if(chrome.windows){
|
|
|
|
chrome.windows.create({
|
|
|
|
url: "popup.html",
|
|
|
|
type: "popup",
|
|
|
|
width: 820,
|
|
|
|
height: 600
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
chrome.tabs.create({url: 'popup.html'})
|
|
|
|
}
|
2024-04-08 22:58:09 +00:00
|
|
|
});
|
2024-05-12 01:16:58 +00:00
|
|
|
|
2024-06-11 23:50:31 +00:00
|
|
|
function createMenu(){
|
2024-05-16 21:27:50 +00:00
|
|
|
chrome.storage.local.set({'isBlock': false}, null);
|
2024-06-11 23:50:31 +00:00
|
|
|
chrome.contextMenus.create({
|
2024-05-12 01:16:58 +00:00
|
|
|
id: "toggleBlocking",
|
2024-05-16 21:27:50 +00:00
|
|
|
title: "Enable License Blocking"
|
2024-05-12 01:16:58 +00:00
|
|
|
});
|
2024-06-11 23:50:31 +00:00
|
|
|
}
|
|
|
|
chrome.runtime.onInstalled.addListener(createMenu)
|
|
|
|
chrome.runtime.onStartup.addListener(createMenu)
|
2024-05-12 01:16:58 +00:00
|
|
|
|
|
|
|
chrome.contextMenus.onClicked.addListener(item => {
|
|
|
|
if(item.menuItemId == "toggleBlocking"){
|
|
|
|
chrome.storage.local.get("isBlock", (value) => {
|
2024-06-21 09:50:42 +00:00
|
|
|
if(value.isBlock){
|
2024-05-16 21:27:50 +00:00
|
|
|
chrome.storage.local.set({'isBlock': false}, null);
|
2024-05-12 01:16:58 +00:00
|
|
|
chrome.contextMenus.update("toggleBlocking",{title: "Enable License Blocking"})
|
|
|
|
} else {
|
2024-05-16 21:27:50 +00:00
|
|
|
chrome.storage.local.set({'isBlock': true}, null);
|
2024-05-12 01:16:58 +00:00
|
|
|
chrome.contextMenus.update("toggleBlocking",{title: "Disable License Blocking"})
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
2024-09-28 01:44:38 +00:00
|
|
|
})
|