@@ -2,32 +2,33 @@ const { promises } = require("fs"); // used for caching
22const path = require ( "path" ) ;
33
44const { ElectronBlocker } = require ( "@cliqz/adblocker-electron" ) ;
5- const { session } = require ( "electron" ) ;
65const fetch = require ( "node-fetch" ) ;
76
87const 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
3031module . exports = { loadAdBlockerEngine } ;
3132if ( require . main === module ) {
32- loadAdBlockerEngine ( false ) ; // Generate the engine without enabling it
33+ loadAdBlockerEngine ( ) ; // Generate the engine without enabling it
3334}
0 commit comments