-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathabp2blocklist.js
More file actions
48 lines (43 loc) · 1.84 KB
/
abp2blocklist.js
File metadata and controls
48 lines (43 loc) · 1.84 KB
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
/*
* This file is part of Adblock Plus <https://adblockplus.org/>,
* Copyright (C) 2006-present eyeo GmbH
*
* Adblock Plus is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 3 as
* published by the Free Software Foundation.
*
* Adblock Plus is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
*/
"use strict";
let readline = require("readline");
let { Filter } = require("./adblockpluscore/lib/filterClasses");
let { ContentBlockerList } = require("./lib/abp2blocklist.js");
var rl = readline.createInterface({ input: process.stdin, terminal: false });
var blockerList = new ContentBlockerList({ merge: "all" });
rl.on("line", line => {
if (/^\s*[^\[\s]/.test(line))
blockerList.addFilter(Filter.fromText(Filter.normalize(line)));
});
rl.on("close", () => {
blockerList.generateRules().then(rules => {
// If the rule set is too huge, JSON.stringify throws
// "RangeError: Invalid string length" on Node.js. As a workaround, print
// each rule individually.
process.stdout.write("[");
if (rules.length > 0) {
// reduce white space in generated json file to save bandwidth and disk space.
// let stringifyRule = rule => JSON.stringify(rule, null, "\t");
let stringifyRule = rule => JSON.stringify(rule);
for (let i = 0; i < rules.length - 1; i++)
process.stdout.write(stringifyRule(rules[i]) + ",");
process.stdout.write(stringifyRule(rules[rules.length - 1]));
}
process.stdout.write("]\n");
});
});