Skip to content

Commit

Permalink
chore: update examples
Browse files Browse the repository at this point in the history
  • Loading branch information
seia-soto committed May 8, 2024
1 parent d3c4786 commit daf342e
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 26 deletions.
27 changes: 20 additions & 7 deletions packages/adblocker-electron-example/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,13 @@ import fetch from 'cross-fetch';
import { app, BrowserWindow } from 'electron';
import { readFileSync, writeFileSync } from 'fs';

import { CosmeticFilter, ElectronBlocker, fullLists, Request } from '@cliqz/adblocker-electron';
import {
CosmeticFilter,
ElectronBlocker,
fullLists,
NetworkFilter,
Request,
} from '@cliqz/adblocker-electron';
import { MatchingContext } from '@cliqz/adblocker/src/engine/engine';

function getUrlToLoad(): string {
Expand Down Expand Up @@ -70,18 +76,25 @@ async function createWindow() {
console.log('style', style.length, url, context);
});

blocker.on('scriptlet-matched', (rule: CosmeticFilter, context: MatchingContext) => {
console.log('script-matched', rule, context);
blocker.on('scriptlet-matched', (rule: CosmeticFilter) => {
console.log('script-matched', rule);
});

blocker.on('extended-rule-matched', (rule: CosmeticFilter, context: MatchingContext) => {
console.log('extended-rule-matched', rule, context);
blocker.on('extended-rule-matched', (rule: CosmeticFilter) => {
console.log('extended-rule-matched', rule);
});

blocker.on('style-rule-matched', (rule: CosmeticFilter, context: MatchingContext) => {
console.log('style-matched', rule, context);
blocker.on('style-rule-matched', (rule: CosmeticFilter) => {
console.log('style-matched', rule);
});

blocker.on(
'filter-matched',
(filter: CosmeticFilter | NetworkFilter, context: MatchingContext) => {
console.log('filter-matched', filter, context);
},
);

mainWindow.loadURL(getUrlToLoad());
mainWindow.webContents.openDevTools();

Expand Down
20 changes: 14 additions & 6 deletions packages/adblocker-playwright-example/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {
CosmeticFilter,
fullLists,
NetworkFilter,
PlaywrightBlocker,
Request,
} from '@cliqz/adblocker-playwright';
Expand Down Expand Up @@ -51,18 +52,25 @@ import * as pw from 'playwright';
console.log('style', url, style.length);
});

blocker.on('scriptlet-matched', (rule: CosmeticFilter, context: MatchingContext) => {
console.log('script-matched', rule, context);
blocker.on('scriptlet-matched', (rule: CosmeticFilter) => {
console.log('script-matched', rule);
});

blocker.on('extended-rule-matched', (rule: CosmeticFilter, context: MatchingContext) => {
console.log('extended-rule-matched', rule, context);
blocker.on('extended-rule-matched', (rule: CosmeticFilter) => {
console.log('extended-rule-matched', rule);
});

blocker.on('style-rule-matched', (rule: CosmeticFilter, context: MatchingContext) => {
console.log('style-matched', rule, context);
blocker.on('style-rule-matched', (rule: CosmeticFilter) => {
console.log('style-matched', rule);
});

blocker.on(
'filter-matched',
(filter: CosmeticFilter | NetworkFilter, context: MatchingContext) => {
console.log('filter-matched', filter, context);
},
);

await page.goto('https://www.mangareader.net/');
await page.screenshot({ path: 'output.png' });
await blocker.disableBlockingInPage(page);
Expand Down
27 changes: 20 additions & 7 deletions packages/adblocker-puppeteer-example/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
import { CosmeticFilter, fullLists, PuppeteerBlocker, Request } from '@cliqz/adblocker-puppeteer';
import {
CosmeticFilter,
fullLists,
NetworkFilter,
PuppeteerBlocker,
Request,
} from '@cliqz/adblocker-puppeteer';
import { MatchingContext } from '@cliqz/adblocker/src/engine/engine';
import { promises as fs } from 'fs';
import fetch from 'node-fetch';
Expand Down Expand Up @@ -64,17 +70,24 @@ function getUrlToLoad(): string {
console.log('style', url, style.length, context);
});

blocker.on('scriptlet-matched', (rule: CosmeticFilter, context: MatchingContext) => {
console.log('script-matched', rule, context);
blocker.on('scriptlet-matched', (rule: CosmeticFilter) => {
console.log('script-matched', rule);
});

blocker.on('extended-rule-matched', (rule: CosmeticFilter, context: MatchingContext) => {
console.log('extended-rule-matched', rule, context);
blocker.on('extended-rule-matched', (rule: CosmeticFilter) => {
console.log('extended-rule-matched', rule);
});

blocker.on('style-rule-matched', (rule: CosmeticFilter, context: MatchingContext) => {
console.log('style-matched', rule, context);
blocker.on('style-rule-matched', (rule: CosmeticFilter) => {
console.log('style-matched', rule);
});

blocker.on(
'filter-matched',
(filter: CosmeticFilter | NetworkFilter, context: MatchingContext) => {
console.log('filter-matched', filter, context);
},
);

await page.goto(getUrlToLoad());
})();
20 changes: 14 additions & 6 deletions packages/adblocker-webextension-example/background.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
CosmeticFilter,
fullLists,
HTMLSelector,
NetworkFilter,
Request,
WebExtensionBlocker,
} from '@cliqz/adblocker-webextension';
Expand Down Expand Up @@ -100,17 +101,24 @@ WebExtensionBlocker.fromLists(fetch, fullLists, {
console.log('style', url, style.length, context);
});

blocker.on('scriptlet-matched', (rule: CosmeticFilter, context: MatchingContext) => {
console.log('script-matched', rule, context);
blocker.on('scriptlet-matched', (rule: CosmeticFilter) => {
console.log('script-matched', rule);
});

blocker.on('extended-rule-matched', (rule: CosmeticFilter, context: MatchingContext) => {
console.log('extended-rule-matched', rule, context);
blocker.on('extended-rule-matched', (rule: CosmeticFilter) => {
console.log('extended-rule-matched', rule);
});

blocker.on('style-rule-matched', (rule: CosmeticFilter, context: MatchingContext) => {
console.log('style-matched', rule, context);
blocker.on('style-rule-matched', (rule: CosmeticFilter) => {
console.log('style-matched', rule);
});

blocker.on(
'filter-matched',
(filter: CosmeticFilter | NetworkFilter, context: MatchingContext) => {
console.log('filter-matched', filter, context);
},
);

console.log('Ready to roll!');
});

0 comments on commit daf342e

Please sign in to comment.