-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbackground.js
40 lines (37 loc) Β· 1.03 KB
/
background.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
console.log("bgscript init");
var blockState = false;
var expiryTime = 1500000;
var timeleft = 0;
function startTimer() {
console.log('timerStart');
blockState = true;
timeleft = expiryTime/1000;
var timerDeduct = setInterval(function () {
timeleft--;
}, 1000);
setTimeout(function () {
blockState = false;
console.log('timerExp');
clearInterval(timeleft);
}, expiryTime);
}
function getTimeLeft(){
return timeleft;
}
chrome.webRequest.onBeforeRequest.addListener(
function (info) {
var blacklist = localStorage["blacklist"].split('\n');
console.log('called',blockState);
for (var match in blacklist) {
var str = blacklist[match];
if (blockState===true && str !== "" && info.url.match(new RegExp(str))) {
return {cancel: blockState};
}
else if(blockState===false) return {cancel: false};
}
return;
},
{
urls: ["http://*/*", "https://*/*"]
}, ["blocking"]
);