-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbackground.js
81 lines (64 loc) · 1.95 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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
chrome.runtime.onInstalled.addListener(() => {
let idToDelete = [];
chrome.declarativeNetRequest.getDynamicRules().then((rules) => {
const privateIpsArray = [ //array of private IP addresses
"*://10.*.*.*",
"*://192.168.*.*",
"*://172.16.*.*",
"*://172.17.*.*",
"*://172.18.*.*",
"*://172.19.*.*",
"*://172.20.*.*",
"*://172.21.*.*",
"*://172.22.*.*",
"*://172.23.*.*",
"*://172.24.*.*",
"*://172.25.*.*",
"*://172.26.*.*",
"*://172.27.*.*",
"*://172.28.*.*",
"*://172.29.*.*",
"*://172.30.*.*",
"*://172.31.*.*",
];
rules.forEach(rule => {
if(privateIpsArray.includes(rule.condition.urlFilter) && rule.priority == 2) {
idToDelete.push(rule.id)
}
})
}).then(() =>{
idToDelete.forEach(id => {
chrome.declarativeNetRequest.updateDynamicRules(
{
//delete all of the private IP allow rules if someone has reinstalled the plugin
removeRuleIds: [id]
})
})
})
})
const blockUrls = [
"*://0*.*.*.*",
"*://1*.*.*.*",
"*://2*.*.*.*",
"*://3*.*.*.*",
"*://4*.*.*.*",
"*://5*.*.*.*",
"*://6*.*.*.*",
"*://7*.*.*.*",
"*://8*.*.*.*",
"*://9*.*.*.*",
];
blockUrls.forEach((domain, index) => {
let id = index + 19;
//the 19 is for the Private IP addresses, 18 of them then + 1 as the index starts from 0
chrome.declarativeNetRequest.updateDynamicRules(
{addRules:[{
"id": id,
"priority": 1,
"action": { "type": "block" },
"condition": {"urlFilter": domain, "resourceTypes": ["main_frame"] }}
],
removeRuleIds: [id]
},
)
})