Safari Content Blocker Converter code and testing extension.
Converts filter rules in AdGuard format to the format supported by Safari.
Install local dependencies by running:
yarn install
Create directories:
mkdir build
mkdir build/converter
touch build/converter/JSConverter.js
Compiles converter and dependencies to one single file in /build
directory.
yarn build
yarn test
yarn convert --1,2,3,4,11,12
const result = SafariContentBlockerConverter.convertArray([ruleOne, ruleTwo], rulesLimit, optimize, advancedBlocking);
The result contains following properties:
- totalConvertedCount: length of content blocker
- convertedCount: length after reducing to limit if provided
- errorsCount: errors count
- overLimit: is limit exceeded flag
- converted: string of content blocker rules
- advancedBlocking: string of advanced blocking rules
- Elemhide rules (##)
- Elemhide exceptions
- Url blocking rules
- Url blocking exceptions
- Script rules (#%#)
- Script rules exceptions
- Extended css elemhide rules (##)
- Scriptlet rules (#%#//scriptlet)
- Scriptlet rules exceptions
Utility safari extension sample. However Safari doesn't log or throw any exception on incorrect rules, this sample extension will find invalid rules and log it to browser console.
yarn extension
- Install this extension to the Safari Extension Builder.
- The result could be found in background page console log.
- update test_filter.txt