Skip to content

Commit

Permalink
Filters compiler should remove cosmetic rules with modifiers for the …
Browse files Browse the repository at this point in the history
…platforms where they're not supported (#655)

* Fix AdguardTeam/FiltersCompiler#152, disabled cosmetic rules modifiers for iOS/Safari

* fix readme
  • Loading branch information
ameshkov authored Aug 10, 2022
1 parent afd8d5f commit cb8009a
Show file tree
Hide file tree
Showing 6 changed files with 91 additions and 7 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
.DS_Store
.idea
.vscode
node_modules
platforms
log.txt
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,11 @@ For each filter, AdGuard compiles two versions: full and optimized. Optimized ve

* `optimization_config.json` - defines the target for the optimization process. AdGuard will try to compress the lists by removing the most rarely used rules until the compression goal (defined in percents) is met.

## Filters compiler customization

`custom_platforms.js` customizes the way filters are compiled for certain platforms. We should use it if we need to
temporary change rules for a platform. In all other cases, we should prefer the default configuration.

## Filters localization

If you want to help with filters translations, you can join us on Crowdin: https://crowdin.com/project/adguard-applications/en#/miscellaneous/filters-registry
Expand Down
77 changes: 77 additions & 0 deletions custom_platforms.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
// Temporary excluding cosmetic rules with modifiers from iOS and Safari:
// https://kb.adguard.com/en/general/how-to-create-your-own-ad-filters#non-basic-rules-modifiers
// The regular expression that does it is: "^\\[.+?\\].*#(\\$|\\@|\\?|\\@){0,2}#"
// TODO: should be removed after iOS and Safari versions are updated with
// SafariConverterLib v2.0.28 or higher.
module.exports = {
"IOS": {
"platform": "ios",
"path": "ios",
"configuration": {
"removeRulePatterns": [
"\\$\\$|\\$\\@\\$",
"\\$(.*,)?mp4",
"\\$(.*,)?replace=",
"\\$stealth",
",stealth",
"\\$cookie",
",cookie",
"important,replace=",
"\\$(.*,)?app",
"\\$protobuf",
"important,protobuf",
"\\$redirect=",
",redirect=",
"\\$redirect-rule=",
",redirect-rule=",
"\\$empty",
",empty",
"\\$webrtc",
"\\$csp=",
"\\$network",
"^\\[.+?\\].*#(\\$|\\@|\\?|\\@){0,2}#"
],
"ignoreRuleHints": false
},
"defines": {
"adguard": true,
"adguard_app_ios": true
}
},
"EXTENSION_SAFARI": {
"platform": "ext_safari",
"path": "extension/safari",
"configuration": {
"removeRulePatterns": [
"\\$\\$|\\$\\@\\$",
"\\$(.*,)?mp4",
"\\$(.*,)?replace=",
"\\$stealth",
",stealth",
"\\$cookie",
",cookie",
"important,replace=",
"\\$(.*,)?app",
"\\$network",
"\\$protobuf",
"important,protobuf",
"\\$csp",
"\\$extension",
",extension",
"\\$redirect=",
",redirect=",
"\\$redirect-rule=",
",redirect-rule=",
"\\$empty",
",empty",
"\\$webrtc",
"^\\[.+?\\].*#(\\$|\\@|\\?|\\@){0,2}#"
],
"ignoreRuleHints": false
},
"defines": {
"adguard": true,
"adguard_ext_safari": true
}
}
}
3 changes: 2 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ if (whitelist.length > 0 || blacklist.length > 0) {
reportPath = null;
}

const customPlatformsConfig = require('./custom_platforms.js');
const platformsPath = path.join(__dirname, './platforms');

compiler.compile(filtersDir, logPath, reportPath, platformsPath, whitelist, blacklist);
compiler.compile(filtersDir, logPath, reportPath, platformsPath, whitelist, blacklist, customPlatformsConfig);
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"name": "adguard-filters",
"version": "1.0.48",
"description": "Adguard filters compiler",
"version": "1.0.49",
"description": "Adguard filters registry",
"homepage": "http://adguard.com",
"dependencies": {
"adguard-filters-compiler": "git+https://github.com/AdguardTeam/FiltersCompiler.git#v1.1.50"
"adguard-filters-compiler": "git+https://github.com/AdguardTeam/FiltersCompiler.git#v1.1.52"
},
"main": "index.js",
"scripts": {
Expand Down
6 changes: 3 additions & 3 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,9 @@ acorn@^8.2.4:
resolved "https://registry.yarnpkg.com/acorn/-/acorn-8.7.0.tgz#90951fde0f8f09df93549481e5fc141445b791cf"
integrity sha512-V/LGr1APy+PXIwKebEWrkZPwoeoF+w1jiOBUmuxuiUIaOHtob8Qc9BTrYo7VuI5fR8tqsy+buA2WFooR5olqvQ==

"adguard-filters-compiler@git+https://github.com/AdguardTeam/FiltersCompiler.git#v1.1.50":
version "1.1.50"
resolved "git+https://github.com/AdguardTeam/FiltersCompiler.git#df4ba77982d238b5a09e2fd2176c6f6582441248"
"adguard-filters-compiler@git+https://github.com/AdguardTeam/FiltersCompiler.git#v1.1.52":
version "1.1.52"
resolved "git+https://github.com/AdguardTeam/FiltersCompiler.git#36923b0027b0394cc2b25fc95dd2b981b0784423"
dependencies:
"@adguard/scriptlets" "^1.6.18"
"@adguard/tsurlfilter" "^1.0.3"
Expand Down

0 comments on commit cb8009a

Please sign in to comment.