Skip to content

Commit 26dd7c5

Browse files
committed
Format blocker file + use window session in adblocker
1 parent 3bbab52 commit 26dd7c5

File tree

2 files changed

+11
-10
lines changed

2 files changed

+11
-10
lines changed

plugins/adblocker/back.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
const { loadAdBlockerEngine } = require("./blocker");
2-
module.exports = () => loadAdBlockerEngine(true);
2+
module.exports = (win) => loadAdBlockerEngine(win.webContents.session);

plugins/adblocker/blocker.js

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,32 +2,33 @@ const { promises } = require("fs"); // used for caching
22
const path = require("path");
33

44
const { ElectronBlocker } = require("@cliqz/adblocker-electron");
5-
const { session } = require("electron");
65
const fetch = require("node-fetch");
76

87
const SOURCES = [
9-
"https://raw.githubusercontent.com/kbinani/adblock-youtube-ads/master/signed.txt"
8+
"https://raw.githubusercontent.com/kbinani/adblock-youtube-ads/master/signed.txt",
109
];
1110

12-
const loadAdBlockerEngine = (enableBlocking = false) =>
11+
const loadAdBlockerEngine = (session = undefined) =>
1312
ElectronBlocker.fromLists(
1413
fetch,
1514
SOURCES,
1615
{},
1716
{
1817
path: path.resolve(__dirname, "ad-blocker-engine.bin"),
1918
read: promises.readFile,
20-
write: promises.writeFile
19+
write: promises.writeFile,
2120
}
2221
)
23-
.then(blocker => {
24-
if (enableBlocking) {
25-
blocker.enableBlockingInSession(session.defaultSession);
22+
.then((blocker) => {
23+
if (session) {
24+
blocker.enableBlockingInSession(session);
25+
} else {
26+
console.log("Successfully generated adBlocker engine.");
2627
}
2728
})
28-
.catch(err => console.log("Error loading adBlocker engine", err));
29+
.catch((err) => console.log("Error loading adBlocker engine", err));
2930

3031
module.exports = { loadAdBlockerEngine };
3132
if (require.main === module) {
32-
loadAdBlockerEngine(false); // Generate the engine without enabling it
33+
loadAdBlockerEngine(); // Generate the engine without enabling it
3334
}

0 commit comments

Comments
 (0)