mirror of
https://github.com/th-ch/youtube-music.git
synced 2026-01-11 10:31:47 +00:00
Generate the adblocker engine only once (by using built-in caching)
This commit is contained in:
@ -35,7 +35,8 @@
|
|||||||
"build": "yarn run clean && build --win --mac --linux",
|
"build": "yarn run clean && build --win --mac --linux",
|
||||||
"build:mac": "yarn run clean && build --mac",
|
"build:mac": "yarn run clean && build --mac",
|
||||||
"build:win": "yarn run clean && build --win",
|
"build:win": "yarn run clean && build --win",
|
||||||
"plugins": "yarn run plugin:autoconfirm",
|
"plugins": "yarn run plugin:adblocker && yarn run plugin:autoconfirm",
|
||||||
|
"plugin:adblocker": "rimraf plugins/adblocker/ad-blocker-engine.bin && node plugins/adblocker/blocker.js",
|
||||||
"plugin:autoconfirm": "yarn run generate:package YoutubeNonStop",
|
"plugin:autoconfirm": "yarn run generate:package YoutubeNonStop",
|
||||||
"release:linux": "yarn run clean && build --linux -p always",
|
"release:linux": "yarn run clean && build --linux -p always",
|
||||||
"release:mac": "yarn run clean && build --mac -p always",
|
"release:mac": "yarn run clean && build --mac -p always",
|
||||||
|
|||||||
1
plugins/adblocker/.gitignore
vendored
Normal file
1
plugins/adblocker/.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
/ad-blocker-engine.bin
|
||||||
@ -1,12 +1,2 @@
|
|||||||
const { ElectronBlocker } = require("@cliqz/adblocker-electron");
|
const { loadAdBlockerEngine } = require("./blocker");
|
||||||
const { session } = require("electron");
|
module.exports = () => loadAdBlockerEngine(true);
|
||||||
const fetch = require("node-fetch");
|
|
||||||
|
|
||||||
const SOURCES = [
|
|
||||||
"https://raw.githubusercontent.com/kbinani/adblock-youtube-ads/master/signed.txt"
|
|
||||||
];
|
|
||||||
|
|
||||||
module.exports = () =>
|
|
||||||
ElectronBlocker.fromLists(fetch, SOURCES)
|
|
||||||
.then(blocker => blocker.enableBlockingInSession(session.defaultSession))
|
|
||||||
.catch(err => console.log("Error loading adBlocker", err));
|
|
||||||
|
|||||||
33
plugins/adblocker/blocker.js
Normal file
33
plugins/adblocker/blocker.js
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
const { promises } = require("fs"); // used for caching
|
||||||
|
const path = require("path");
|
||||||
|
|
||||||
|
const { ElectronBlocker } = require("@cliqz/adblocker-electron");
|
||||||
|
const { session } = require("electron");
|
||||||
|
const fetch = require("node-fetch");
|
||||||
|
|
||||||
|
const SOURCES = [
|
||||||
|
"https://raw.githubusercontent.com/kbinani/adblock-youtube-ads/master/signed.txt"
|
||||||
|
];
|
||||||
|
|
||||||
|
const loadAdBlockerEngine = (enableBlocking = false) =>
|
||||||
|
ElectronBlocker.fromLists(
|
||||||
|
fetch,
|
||||||
|
SOURCES,
|
||||||
|
{},
|
||||||
|
{
|
||||||
|
path: path.resolve(__dirname, "ad-blocker-engine.bin"),
|
||||||
|
read: promises.readFile,
|
||||||
|
write: promises.writeFile
|
||||||
|
}
|
||||||
|
)
|
||||||
|
.then(blocker => {
|
||||||
|
if (enableBlocking) {
|
||||||
|
blocker.enableBlockingInSession(session.defaultSession);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.catch(err => console.log("Error loading adBlocker engine", err));
|
||||||
|
|
||||||
|
module.exports = { loadAdBlockerEngine };
|
||||||
|
if (require.main === module) {
|
||||||
|
loadAdBlockerEngine(false); // Generate the engine without enabling it
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user