Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
alwaysOnTop: store.get('options.alwaysOnTop'),
toolbar: false,
backgroundColor: '#00000000',
fullscreen: store.get('options.launchFullscreen')
});
// Connect Adblocker To Window if Enabled
if (store.get('options.adblock')) {
let engineCachePath = path.join(
app.getPath('userData'),
'adblock-engine-cache.txt'
);
if (fs.existsSync(engineCachePath)) {
console.log('Adblock engine cache found. Loading it into app.');
var engine = await ElectronBlocker.deserialize(
fs.readFileSync(engineCachePath)
);
} else {
var engine = await ElectronBlocker.fromLists(fetch, fullLists);
}
engine.enableBlockingInSession(session.defaultSession);
// Backup Engine Cache to Disk
fs.writeFile(engineCachePath, engine.serialize(), err => {
if (err) throw err;
console.log('Adblock Engine file cache has been updated!');
});
}
// Reset The Windows Size and Location
let windowDetails = store.get('options.windowDetails');
// - https://raw.githubusercontent.com/uBlockOrigin/uAssets/master/filters/privacy.txt
engine = await ElectronBlocker.fromPrebuiltAdsAndTracking(fetch);
try {
await fs.writeFile(path, engine.serialize());
} catch (err) {
if (err) return console.error(err);
}
};
if (existsSync(path)) {
try {
const buffer = await fs.readFile(resolve(path));
try {
engine = ElectronBlocker.deserialize(buffer);
} catch (e) {
return downloadFilters();
}
} catch (err) {
return console.error(err);
}
} else {
return downloadFilters();
}
};
// - https://raw.githubusercontent.com/uBlockOrigin/uAssets/master/filters/privacy.txt
engine = await ElectronBlocker.fromPrebuiltAdsAndTracking(fetch);
try {
await fs.writeFile(path, engine.serialize());
} catch (err) {
if (err) return console.error(err);
}
};
if (existsSync(path)) {
try {
const buffer = await fs.readFile(resolve(path));
try {
engine = ElectronBlocker.deserialize(buffer);
} catch (e) {
return downloadFilters();
}
} catch (err) {
return console.error(err);
}
} else {
return downloadFilters();
}
};
});
// Connect Adblocker To Window if Enabled
if (store.get('options.adblock')) {
let engineCachePath = path.join(
app.getPath('userData'),
'adblock-engine-cache.txt'
);
if (fs.existsSync(engineCachePath)) {
console.log('Adblock engine cache found. Loading it into app.');
var engine = await ElectronBlocker.deserialize(
fs.readFileSync(engineCachePath)
);
} else {
var engine = await ElectronBlocker.fromLists(fetch, fullLists);
}
engine.enableBlockingInSession(session.defaultSession);
// Backup Engine Cache to Disk
fs.writeFile(engineCachePath, engine.serialize(), err => {
if (err) throw err;
console.log('Adblock Engine file cache has been updated!');
});
}
// Reset The Windows Size and Location
let windowDetails = store.get('options.windowDetails');
let relaunchWindowDetails = store.get('relaunch.windowDetails');
if (relaunchWindowDetails) {
mainWindow.setSize(
relaunchWindowDetails.size[0],
const downloadFilters = async () => {
// Load lists to perform ads and tracking blocking:
//
// - https://easylist.to/easylist/easylist.txt
// - https://pgl.yoyo.org/adservers/serverlist.php?hostformat=adblockplus&showintro=1&mimetype=plaintext
// - https://raw.githubusercontent.com/uBlockOrigin/uAssets/master/filters/resource-abuse.txt
// - https://raw.githubusercontent.com/uBlockOrigin/uAssets/master/filters/badware.txt
// - https://raw.githubusercontent.com/uBlockOrigin/uAssets/master/filters/filters.txt
// - https://raw.githubusercontent.com/uBlockOrigin/uAssets/master/filters/unbreak.txt
//
// - https://easylist.to/easylist/easyprivacy.txt
// - https://raw.githubusercontent.com/uBlockOrigin/uAssets/master/filters/privacy.txt
engine = await ElectronBlocker.fromPrebuiltAdsAndTracking(fetch);
try {
await fs.writeFile(path, engine.serialize());
} catch (err) {
if (err) return console.error(err);
}
};
const downloadFilters = async () => {
// Load lists to perform ads and tracking blocking:
//
// - https://easylist.to/easylist/easylist.txt
// - https://pgl.yoyo.org/adservers/serverlist.php?hostformat=adblockplus&showintro=1&mimetype=plaintext
// - https://raw.githubusercontent.com/uBlockOrigin/uAssets/master/filters/resource-abuse.txt
// - https://raw.githubusercontent.com/uBlockOrigin/uAssets/master/filters/badware.txt
// - https://raw.githubusercontent.com/uBlockOrigin/uAssets/master/filters/filters.txt
// - https://raw.githubusercontent.com/uBlockOrigin/uAssets/master/filters/unbreak.txt
//
// - https://easylist.to/easylist/easyprivacy.txt
// - https://raw.githubusercontent.com/uBlockOrigin/uAssets/master/filters/privacy.txt
engine = await ElectronBlocker.fromPrebuiltAdsAndTracking(fetch);
try {
await fs.writeFile(path, engine.serialize());
} catch (err) {
if (err) return console.error(err);
}
};
const createAdblocker = sessionList => {
const blocklistsFolder = path.join(app.getPath("appData"), "blocklists")
// Read all filter files from the blocklists folder (including user added)
let filters = ""
try {
for (const file of fs.readdirSync(blocklistsFolder)) {
if (file.endsWith(".txt")) {
filters += loadBlocklist(file)
}
}
} catch (e) {
console.log("Failed to read the files from blocklists folder", e)
}
blocker = ElectronBlocker.parse(filters)
enableAdblocker(sessionList)
}
ipcMain.on("adblock-enable", (_, sessionList) => {
async function createWindow() {
mainWindow = new BrowserWindow({
height: 600,
width: 800,
});
if (session.defaultSession === undefined) {
throw new Error('defaultSession is undefined');
}
const blocker = await ElectronBlocker.fromLists(fetch, fullLists, {
enableCompression: true,
});
blocker.enableBlockingInSession(session.defaultSession);
blocker.on('request-blocked', (request: Request) => {
console.log('blocked', request.tabId, request.url);
});
blocker.on('request-redirected', (request: Request) => {
console.log('redirected', request.tabId, request.url);
});
blocker.on('request-whitelisted', (request: Request) => {
console.log('whitelisted', request.tabId, request.url);
});
const {width, height} = electron.screen.getPrimaryDisplay().size
youtubeWindow = new BrowserWindow({
height: height * 0.50,
width: width * 0.5,
frame: false,
transparent: false,
icon: path.join(__dirname, 'app/build/icon.png'),
alwaysOnTop: false,
show: false
})
youtubeWindow.loadURL('file://' + __dirname + '/app/index.html')
ElectronBlocker.fromPrebuiltAdsAndTracking(fetch).then((blocker) => {
blocker.enableBlockingInSession(session.defaultSession)
})
youtubeWindow.once('ready-to-show', () => {
ipcMain.on('can-show', (event, arg) => {
youtubeWindow.show()
})
})
})