-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbackground.js
90 lines (88 loc) · 3.06 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
82
83
84
85
86
87
88
89
90
const blockingRules = [
{
"id": 1,
"priority": 1,
"action": { "type": "block" },
"condition": { "urlFilter": "*://*.doubleclick.net/*", "resourceTypes": ["script", "image", "xmlhttprequest"] }
},
{
"id": 2,
"priority": 1,
"action": { "type": "block" },
"condition": { "urlFilter": "*://partner.googleadservices.com/*", "resourceTypes": ["script", "image", "xmlhttprequest"] }
},
{
"id": 3,
"priority": 1,
"action": { "type": "block" },
"condition": { "urlFilter": "*://*.googlesyndication.com/*", "resourceTypes": ["script", "image", "xmlhttprequest"] }
},
{
"id": 4,
"priority": 1,
"action": { "type": "block" },
"condition": { "urlFilter": "*://*.google-analytics.com/*", "resourceTypes": ["script", "image", "xmlhttprequest"] }
},
{
"id": 5,
"priority": 1,
"action": { "type": "block" },
"condition": { "urlFilter": "*://creative.ak.fbcdn.net/*", "resourceTypes": ["script", "image", "xmlhttprequest"] }
},
{
"id": 6,
"priority": 1,
"action": { "type": "block" },
"condition": { "urlFilter": "*://*.adbrite.com/*", "resourceTypes": ["script", "image", "xmlhttprequest"] }
},
{
"id": 7,
"priority": 1,
"action": { "type": "block" },
"condition": { "urlFilter": "*://*.exponential.com/*", "resourceTypes": ["script", "image", "xmlhttprequest"] }
},
{
"id": 8,
"priority": 1,
"action": { "type": "block" },
"condition": { "urlFilter": "*://*.quantserve.com/*", "resourceTypes": ["script", "image", "xmlhttprequest"] }
},
{
"id": 9,
"priority": 1,
"action": { "type": "block" },
"condition": { "urlFilter": "*://*.scorecardresearch.com/*", "resourceTypes": ["script", "image", "xmlhttprequest"] }
},
{
"id": 10,
"priority": 1,
"action": { "type": "block" },
"condition": { "urlFilter": "*://*.zedo.com/*", "resourceTypes": ["script", "image", "xmlhttprequest"] }
},
{
"id": 11,
"priority": 1,
"action": { "type": "block" },
"condition": { "urlFilter": "*://*.leetcode.com/*", "resourceTypes": ["script", "image", "xmlhttprequest"] }
}
// Add your own URLs to block here -
// {
// "id": serial_id_number,
// "priority": 1,
// "action": { "type": "block" },
// "condition": { "urlFilter": "*://*.your_url/*", "resourceTypes": ["script", "image", "xmlhttprequest"] }
// }
];
chrome.declarativeNetRequest.updateDynamicRules(
{
addRules: blockingRules,
removeRuleIds: blockingRules.map(rule => rule.id)
},
() => {
if (chrome.runtime.lastError) {
console.error("Error setting rules:", chrome.runtime.lastError);
} else {
console.log("Blocking rules successfully applied.");
}
}
);