mirror of
https://github.com/th-ch/youtube-music.git
synced 2026-01-16 20:52:06 +00:00
Format blocker file + use window session in adblocker
This commit is contained in:
@ -1,2 +1,2 @@
|
|||||||
const { loadAdBlockerEngine } = require("./blocker");
|
const { loadAdBlockerEngine } = require("./blocker");
|
||||||
module.exports = () => loadAdBlockerEngine(true);
|
module.exports = (win) => loadAdBlockerEngine(win.webContents.session);
|
||||||
|
|||||||
@ -2,14 +2,13 @@ const { promises } = require("fs"); // used for caching
|
|||||||
const path = require("path");
|
const path = require("path");
|
||||||
|
|
||||||
const { ElectronBlocker } = require("@cliqz/adblocker-electron");
|
const { ElectronBlocker } = require("@cliqz/adblocker-electron");
|
||||||
const { session } = require("electron");
|
|
||||||
const fetch = require("node-fetch");
|
const fetch = require("node-fetch");
|
||||||
|
|
||||||
const SOURCES = [
|
const SOURCES = [
|
||||||
"https://raw.githubusercontent.com/kbinani/adblock-youtube-ads/master/signed.txt"
|
"https://raw.githubusercontent.com/kbinani/adblock-youtube-ads/master/signed.txt",
|
||||||
];
|
];
|
||||||
|
|
||||||
const loadAdBlockerEngine = (enableBlocking = false) =>
|
const loadAdBlockerEngine = (session = undefined) =>
|
||||||
ElectronBlocker.fromLists(
|
ElectronBlocker.fromLists(
|
||||||
fetch,
|
fetch,
|
||||||
SOURCES,
|
SOURCES,
|
||||||
@ -17,17 +16,19 @@ const loadAdBlockerEngine = (enableBlocking = false) =>
|
|||||||
{
|
{
|
||||||
path: path.resolve(__dirname, "ad-blocker-engine.bin"),
|
path: path.resolve(__dirname, "ad-blocker-engine.bin"),
|
||||||
read: promises.readFile,
|
read: promises.readFile,
|
||||||
write: promises.writeFile
|
write: promises.writeFile,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
.then(blocker => {
|
.then((blocker) => {
|
||||||
if (enableBlocking) {
|
if (session) {
|
||||||
blocker.enableBlockingInSession(session.defaultSession);
|
blocker.enableBlockingInSession(session);
|
||||||
|
} else {
|
||||||
|
console.log("Successfully generated adBlocker engine.");
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.catch(err => console.log("Error loading adBlocker engine", err));
|
.catch((err) => console.log("Error loading adBlocker engine", err));
|
||||||
|
|
||||||
module.exports = { loadAdBlockerEngine };
|
module.exports = { loadAdBlockerEngine };
|
||||||
if (require.main === module) {
|
if (require.main === module) {
|
||||||
loadAdBlockerEngine(false); // Generate the engine without enabling it
|
loadAdBlockerEngine(); // Generate the engine without enabling it
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user