-
Notifications
You must be signed in to change notification settings - Fork 101
/
generateBlockRules.js
54 lines (44 loc) · 1.28 KB
/
generateBlockRules.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
// This is used to generate the block rules for Manifest V3 from the block rules in Manifest V2.
import { blockUrls } from "../../src/data/rules.js";
function generateDeclarativeNetRules() {
const result = [];
let lastId = 1;
const addRule = (blockRule) => {
const newRule = {
id: lastId++,
priority: 1,
action: { type: "block" },
condition: {
urlFilter: blockRule.r,
resourceTypes: ["script", "stylesheet", "xmlhttprequest", "image"],
},
};
if (blockRule.e) {
newRule.condition.excludedInitiatorDomains = blockRule.e.slice();
}
result.push(newRule);
};
for (const blockRule of blockUrls.common) {
addRule(blockRule);
}
for (const blockRules of Object.values(blockUrls.common_groups)) {
for (const blockRule of blockRules) {
addRule(blockRule);
}
}
for (const [domain, url] of Object.entries(blockUrls.specific)) {
const newRule = {
id: lastId++,
priority: 1,
action: { type: "block" },
condition: {
urlFilter: url[0],
resourceTypes: ["script", "stylesheet", "xmlhttprequest", "image"],
initiatorDomains: [domain],
},
};
result.push(newRule);
}
console.log(JSON.stringify(result, null, "\t"));
}
generateDeclarativeNetRules();