-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbackground.js
34 lines (27 loc) · 946 Bytes
/
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
'use strict'
const unblocked = []
// detect whether a site should be blocked
function scan_url(details) {
const url = details.url;
chrome.storage.sync.get(["unblocked"], function (results) {
for (let regex of results.unblocked) {
if (url.match(regex)) {
console.log(`allowed ${url}`);
return;
}
}
});
chrome.storage.sync.get(["blocked"], function (results) {
for (let b of results.blocked) {
const regex = new RegExp(b);
if (details.parentFrameId != -1) return;
if (!url.startsWith('chrome://') && url.match(regex)) {
chrome.tabs.update({url: chrome.runtime.getURL("redirect.html")});
console.log(`blocked ${url}`);
return;
}
}
console.log(`allowed ${url}`);
});
}
chrome.webNavigation.onBeforeNavigate.addListener(scan_url);