-
Notifications
You must be signed in to change notification settings - Fork 346
/
Copy pathgenerate-easylists.js
26 lines (22 loc) · 1.13 KB
/
generate-easylists.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
const path = require('path');
const fs = require('fs');
var rootPath = path.resolve(__dirname, 'corporations');
var files = fs.readdirSync(rootPath)
.filter(dir => fs.statSync(path.resolve(rootPath, dir)).isDirectory())
.map(dir => fs.readdirSync(path.resolve(rootPath, dir))
.filter(filename => !filename.includes('.easylist') && !filename.includes('README'))
.map(filename => path.resolve(rootPath, dir, filename)))
.reduce((all, dirFiles) => all.concat(dirFiles), [])
files.forEach(file => {
var fileContents = fs.readFileSync(file, { encoding: 'utf-8' });
var easy = '[Adblock Plus 2.0]\n' +
fileContents.split('\n')
.map(line => line.match(/^0\.0\.0\.0[\s]+([^#\s]*)/))
.filter(result => result != null)
.map(result => result[1])
.map(domain => [ `||${domain}^`,
`||${domain}^$popup`,
`||${domain}^$third-party` ].join('\n'))
.join('\n');
fs.writeFileSync(file + '.easylist', easy);
})