Content Blocker converter swift code
Converts filter rules in AdGuard format to the format supported by Safari.
swift build
swift test
let result: ConversionResult? = ContentBlockerConverter.convertArray(
rules: [String],
safariVersion: SafariVersions = .DEFAULT,
optimize: Bool = false,
advancedBlocking: Bool = false
advancedBlockingFormat: AdvancedBlockingFormat = .json
);
Please note, that safariVersion
must be an instance of enum SafariVersions.
The result contains following properties:
ConverterTool [--safari-version <safari-version>] [--optimize <optimize>] [--advanced-blocking <advanced-blocking>] [--advanced-blocking-format <advanced-blocking-format>] [<rules>]
e.g.
cat rules.txt | ./ConverterTool --safari-version 13 --optimize false --advanced-blocking true --advanced-blocking-format txt
The tool then reads stdin line by line for rule until an empty line.
Push a new tag in v*.*.*
format, then provided github action is intended to build and publish new release with an asset binary.
After installation the build process occurs and binary file will be copied to bin directory
jsonFromRules(rules, advancedBlocking, safariVersion, converterToolPath)
- method to convert rules into JSON
getConverterVersion
- returns Safari Converter Lib version
if-domain
and unless-domain
triggers. That's why rules like example.org,~foo.example.orgs
are invalid. Feature request to WebKit to allow such rules.ping
modifier are ignored (until #18 is solved)specifichide
modifier disables all specific element hiding rules for the same level domain and doesn't influence on subdomains or top-level domains, i.e. the rule @@||sub.example.org^$specifichide
doesn't disable test.sub.example.org##.banner
and example.org##.banner
generichide
, elemhide
, specifichide
and jsinject
modifiers can be used only as a single modifier in a rule.denyallow
rulesA rule with the denyallow
modifier will be converted into a blocking rule and additional exception rules.
For example:
Generic rule *$denyallow=x.com,image,domain=a.com
will be converted to
*$image,domain=a.com
@@||x.com$image,domain=a.com
Blocking rule /banner.png$image,denyallow=test1.com|test2.com,domain=example.org
will be converted to
/banner.png$image,domain=example.org
@@||test1.com/banner.png$image,domain=example.org
@@||test1.com/*/banner.png$image,domain=example.org
@@||test2.com/banner.png$image,domain=example.org
@@||test2.com/*/banner.png$image,domain=example.org
Exception rule @@/banner.png$image,denyallow=test.com,domain=example.org
will be converted to
@@/banner.png$image,domain=example.org
||test.com/banner.png$image,domain=example.org,important
||test.com/*/banner.png$image,domain=example.org,important