fix: use ghostry adblocker

This commit is contained in:
JellyBrick
2024-12-19 19:53:43 +09:00
parent a837987e70
commit be04d66aa8
5 changed files with 61 additions and 103 deletions

View File

@ -2,7 +2,7 @@
import path from 'node:path';
import fs, { promises } from 'node:fs';
import { ElectronBlocker } from '@cliqz/adblocker-electron';
import { ElectronBlocker } from '@ghostery/adblocker-electron';
import { app, net } from 'electron';
const SOURCES = [
@ -55,6 +55,7 @@ export const loadAdBlockerEngine = async (
(url: string) => net.fetch(url),
lists,
{
enableCompression: true,
// When generating the engine for caching, do not load network filters
// So that enhancing the session works as expected
// Allowing to define multiple webRequest listeners
@ -66,7 +67,7 @@ export const loadAdBlockerEngine = async (
blocker.enableBlockingInSession(session);
}
} catch (error) {
console.log('Error loading adBlocker engine', error);
console.error('Error loading adBlocker engine', error);
}
};

View File

@ -8,7 +8,6 @@ import {
unloadAdBlockerEngine,
} from './blocker';
import injectCliqzPreload from './injectors/inject-cliqz-preload';
import { inject, isInjected } from './injectors/inject';
import { loadAdSpeedup } from './adSpeedup';
@ -134,18 +133,13 @@ export default createPlugin({
async start({ getConfig }) {
const config = await getConfig();
if (config.blocker === blockers.WithBlocklists) {
// Preload adblocker to inject scripts/styles
await injectCliqzPreload();
} else if (config.blocker === blockers.InPlayer && !isInjected()) {
if (config.blocker === blockers.InPlayer && !isInjected()) {
inject(contextBridge);
await webFrame.executeJavaScript(this.script);
}
},
async onConfigChange(newConfig) {
if (newConfig.blocker === blockers.WithBlocklists) {
await injectCliqzPreload();
} else if (newConfig.blocker === blockers.InPlayer && !isInjected()) {
if (newConfig.blocker === blockers.InPlayer && !isInjected()) {
inject(contextBridge);
await webFrame.executeJavaScript(this.script);
}

View File

@ -1,3 +1,3 @@
export default async () => {
await import('@cliqz/adblocker-electron-preload');
await import('@ghostery/adblocker-electron-preload');
};