forked from lulzsun/blitz-app-adblock
-
Notifications
You must be signed in to change notification settings - Fork 0
/
js.js
58 lines (52 loc) · 1.75 KB
/
js.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
var filterEngine =
`
try {
const fs = require('fs');
const { FiltersEngine, Request } = require('./adblocker.umd.min.js');
const filters =
fs.readFileSync(require.resolve('./easylist.txt'), 'utf-8') + '\\n' +
fs.readFileSync(require.resolve('./easyprivacy.txt'), 'utf-8') + '\\n' +
fs.readFileSync(require.resolve('./ublock-ads.txt'), 'utf-8') + '\\n' +
fs.readFileSync(require.resolve('./ublock-privacy.txt'), 'utf-8') + '\\n' +
fs.readFileSync(require.resolve('./peter-lowe-list.txt'), 'utf-8') + '\\ngoogleoptimize.com\\n';
const engine = FiltersEngine.parse(filters);
windowInstance.webContents.session.webRequest.onBeforeRequest({ urls: ['*://*/*'] }, (details, callback) => {
const {match} = engine.match(Request.fromRawDetails({ url: details.url }));
if (match == true) {
log.info('BLOCKED:', details.url);
callback({cancel: true});
} else {
callback({cancel: false});
}
});
} catch (error) {
log.error(error);
}
`
filterEngine = compress(filterEngine);
var autoGuest =
`autoGuest();
function autoGuest() {
var buttons = document.getElementsByTagName('button');
for (var i = 0; i < buttons.length; i++) {
if (buttons[i].getAttribute('label') == 'Login As Guest') {
buttons[i].click();
return;
}
}
setTimeout(autoGuest, 1000);
}
`
autoGuest = compress(autoGuest);
function compress(uncompressedJs) {
var compressedJs = '';
var stringArr = uncompressedJs.split('\n');
for (var i = 0; i < stringArr.length; i++) {
compressedJs += stringArr[i].trim();
}
return compressedJs;
}
module.exports = {
filterEngine: filterEngine,
autoGuest: autoGuest
};