-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathblock_sites.js
42 lines (36 loc) · 1.35 KB
/
block_sites.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
//block_sites.js
var newLink;
var found = false;
chrome.tabs.onUpdated.addListener((tabId, changeInfo, tab) => {
console.log(tab.url);
var url = new URL(tab.url);
url = String(url.hostname);
url = url.split(".")
if (url.length-1 == 2 && url[0].startsWith("www"))url = url.slice(1).join(".");
else url = url.join(".");
link = "*://*."+url+"/*";
console.log(link);
if(chrome.webRequest.onBeforeRequest.hasListener(blockRequest))
chrome.webRequest.onBeforeRequest.removeListener(blockRequest);
var rawr = localStorage.getItem("nyaa");
rawr = rawr.split(',').slice(1);
console.log(rawr);
for (let i = 0; i < rawr.length; i += 1){
console.log(rawr[i]);
var url = new URL(rawr[i]);
url = String(url.hostname);
url = url.split(".")
if (url.length-1 == 2 && url[0].startsWith("www"))url = url.slice(1).join(".");
else url = url.join(".");
rawr[i] = "*://*."+url+"/*";
}
console.log(rawr);
chrome.webRequest.onBeforeRequest.addListener(blockRequest, {urls: rawr }, ['blocking']);
if (rawr.includes(link) == true && (changeInfo.status == "complete" && tab.status == "complete" && tab.url != undefined)) alert("You are currently in a Pomodoro Session!\nPlease focus.");
})
function updateArray(arr) {
badLinks = arr.split(", ");
}
function blockRequest(details) {
return {cancel: true};
}