mirror of
https://github.com/th-ch/youtube-music.git
synced 2026-01-17 05:02:06 +00:00
Adblocker - advanced options (caching or not, additional lists)
This commit is contained in:
@ -1,2 +1,7 @@
|
|||||||
const { loadAdBlockerEngine } = require("./blocker");
|
const { loadAdBlockerEngine } = require("./blocker");
|
||||||
module.exports = (win) => loadAdBlockerEngine(win.webContents.session);
|
module.exports = (win, options) =>
|
||||||
|
loadAdBlockerEngine(
|
||||||
|
win.webContents.session,
|
||||||
|
options.cache,
|
||||||
|
options.additionalBlockLists
|
||||||
|
);
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
const { promises } = require("fs"); // used for caching
|
const { existsSync, promises, unlinkSync } = 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");
|
||||||
@ -8,16 +8,28 @@ 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 = (session = undefined) =>
|
const loadAdBlockerEngine = (
|
||||||
|
session = undefined,
|
||||||
|
cache = true,
|
||||||
|
additionalBlockLists = []
|
||||||
|
) => {
|
||||||
|
const adBlockerCache = path.resolve(__dirname, "ad-blocker-engine.bin");
|
||||||
|
if (!cache && existsSync(adBlockerCache)) {
|
||||||
|
unlinkSync(adBlockerCache);
|
||||||
|
}
|
||||||
|
const cachingOptions = cache
|
||||||
|
? {
|
||||||
|
path: adBlockerCache,
|
||||||
|
read: promises.readFile,
|
||||||
|
write: promises.writeFile,
|
||||||
|
}
|
||||||
|
: undefined;
|
||||||
|
|
||||||
ElectronBlocker.fromLists(
|
ElectronBlocker.fromLists(
|
||||||
fetch,
|
fetch,
|
||||||
SOURCES,
|
[...SOURCES, ...additionalBlockLists],
|
||||||
{},
|
{},
|
||||||
{
|
cachingOptions
|
||||||
path: path.resolve(__dirname, "ad-blocker-engine.bin"),
|
|
||||||
read: promises.readFile,
|
|
||||||
write: promises.writeFile,
|
|
||||||
}
|
|
||||||
)
|
)
|
||||||
.then((blocker) => {
|
.then((blocker) => {
|
||||||
if (session) {
|
if (session) {
|
||||||
@ -27,6 +39,7 @@ const loadAdBlockerEngine = (session = undefined) =>
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
.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) {
|
||||||
|
|||||||
Reference in New Issue
Block a user