Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
Swift Safari Converter
Content Blocker converter swift code
Safari Content Blocker
Converts filter rules in AdGuard format to the format supported by Safari.
How to build:
swift build
Tests:
swift test
How to use converter:
let result: ConversionResult? = ContentBlockerConverter.convertArray(
rules: [String], limit: Int = 0, optimize: Bool = false, advancedBlocking: Bool = false
);
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: json string of content blocker rules
- advancedBlocking: json string of advanced blocking rules
How to use converter from command line:
./ConverterTool -limit=0 -optimize=true -advancedBlocking=false <<STDIN -o other --options
test_rule_one
test_rule_two
STDIN
The tool then reads stdin line by line for rule until an empty line.
How to release on Github
Push a new tag in v*.*.*
format, then provided github action is intended to build and publish new release with an asset binary.
Supported AdGuard rules types:
Basic content blocker format:
- Elemhide rules (##)
- Elemhide exceptions
- Url blocking rules
- Url blocking exceptions
Extended Advanced blocking types:
- Script rules (#%#)
- Script rules exceptions
- Extended css elemhide rules (##)
- Scriptlet rules (#%#//scriptlet)
- Scriptlet rules exceptions
Third-party dependencies
- Punycode (https://github.com/gumob/PunycodeSwift.git)
Use as node module
Requirements:
- Swift 4 or higher
After installation the build process occurs and binary file will be copied to bin directory
API
jsonFromRules(rules, advancedBlocking, log)
- method to convert rules into JSON
- rules - array of rules
- advancedBlocking - if we need advanced blocking content (boolean)
- logger
getConverterVersion
- returns Safari Converter Lib version
Github
link |
Stars: 7 |
You may find interesting
Dependencies
Releases
v1.1.6 - 2020-12-24T14:13:20
- Updated converter binary
v1.1.5 - 2020-12-21T12:40:08
- Updated converter binary
v1.1.4 - 2020-12-03T14:53:39
- Updated converter binary
v1.1.3 - 2020-12-01T09:52:25
- Updated converter binary
v1.1.2 - 2020-11-17T21:32:11
- Updated converter binary
v1.1.1 - 2020-11-06T10:22:09
- Updated converter binary
v1.1.0 - 2020-10-29T09:40:13
- Compact domain sensitive css rules #2
- Fix network rules parsing
- Fix ubo-scriptlets conversion
v1.0.1 - 2020-10-20T12:48:53
- Feature Request: Support uBO's filter rules: #1
v1.0.0 - 2020-10-16T14:44:18
Performance is greatly improved
v0.1.1 - 2020-09-24T13:42:10
- Added log message
v0.1.0 - 2020-09-23T15:10:07
Converter binary