forked from lulzsun/blitz-app-adblock
-
Notifications
You must be signed in to change notification settings - Fork 0
/
blitz-app-adblock.js
129 lines (109 loc) · 4.49 KB
/
blitz-app-adblock.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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
const fs = require('fs');
const os = require('os');
const ps = require('ps4js');
const asar = require('asar');
const path = require('path');
const io = require('./io');
const js = require('./js');
var appPath = '';
var noUpdate = false;
var autoGuest = false;
async function start() {
try {
argumentsHandler();
await killBlitz();
// mac os app path
if (process.platform === 'darwin') {
var dir = os.homedir() + '/Applications/Blitz.app/Contents/Resources';
if(fs.existsSync(dir)) {
appPath = dir
}
else {
appPath = '/Applications/Blitz.app/Contents/Resources';
}
}
// windows app path
else if (process.platform === 'win32') {
appPath = path.join(process.env.APPDATA, '../Local/Programs/Blitz/resources');
}
if(!appPath || !fs.existsSync(`${appPath}/app.asar`)) {
console.log("app.asar not found!");
}
else {
console.log('Extracting app.asar...');
asar.extractAll(`${appPath}/app.asar`, `${appPath}/app/`);
console.log('Downloading ad & tracking filters...');
await io.downloadFile('https://easylist.to/easylist/easylist.txt', `${appPath}/app/src/easylist.txt`);
await io.downloadFile('https://easylist.to/easylist/easyprivacy.txt', `${appPath}/app/src/easyprivacy.txt`);
await io.downloadFile('https://raw.githubusercontent.com/uBlockOrigin/uAssets/master/filters/filters.txt', `${appPath}/app/src/ublock-ads.txt`);
await io.downloadFile('https://raw.githubusercontent.com/uBlockOrigin/uAssets/master/filters/privacy.txt', `${appPath}/app/src/ublock-privacy.txt`);
await io.downloadFile('https://pgl.yoyo.org/adservers/serverlist.php?hostformat=adblock&showintro=1&mimetype=plaintext', `${appPath}/app/src/peter-lowe-list.txt`);
console.log('Patching...');
// copy adblocker lib to src
if(fs.existsSync(`adblocker.umd.min.js`))
io.copyFile('adblocker.umd.min.js', `${appPath}/app/src/adblocker.umd.min.js`)
else io.copyFile('./build/adblocker.umd.min.js', `${appPath}/app/src/adblocker.umd.min.js`)
// start writing our payload to createWindow.js
io.modifyFileAfterContext(js.filterEngine, `${appPath}/app/src/createWindow.js`, 'function interceptRequests(windowInstance) {');
io.modifyFileAfterContext('session: true,', `${appPath}/app/src/createWindow.js`, 'webPreferences: {');
// optional features
if (noUpdate) io.modifyFileAtLine('', `${appPath}/app/src/autoUpdater/index.js`, 46);
if (autoGuest) io.modifyFileAtLine(js.autoGuest, `${appPath}/app/src/preload.js`, 18);
// repack
console.log('Repacking app.asar...');
await asar.createPackage(`${appPath}/app/`, `${appPath}/app.asar`);
// cleanup
console.log('Cleaning up directory...');
io.deleteFolder(`${appPath}/app/`);
console.log('\r\nPatching complete! GLHF :)');
}
}
catch (error) {
console.log('\n');
console.log(error);
}
console.log();
require('readline')
.createInterface(process.stdin, process.stdout)
.question('Press ENTER to quit...', function(){
process.exit();
});
}
function killBlitz() {
console.log('Checking for Blitz...');
return new Promise(resolve => {
var pid;
ps.list(function(err, results) {
if (err)
throw new Error( err );
results.forEach(process => {
if(process.command.startsWith('Blitz')) {
if(!pid)
console.log('Closing out Blitz...');
pid = process.pid;
ps.kill(pid, function(err, stdout) {
if (err)
throw new Error(err);
});
}
});
resolve();
});
});
}
function argumentsHandler() {
var args = process.argv.slice(2);
for (var i = 0; i < args.length; i++) {
switch (args[i]) {
case '-noupdate':
noUpdate = true;
break;
case '-autoguest':
autoGuest = true;
break;
default:
console.log(`Unknown argument: '` + args[i] + `'`);
}
}
}
start();