Skip to content

Commit

Permalink
Add support for EasyList { remove: true } cosmetic filter syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
gorhill committed Nov 14, 2024
1 parent 2e745f9 commit ff5fc61
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions src/js/static-filtering-parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -3345,10 +3345,13 @@ class ExtSelectorCompiler {
// We have an Adguard/ABP cosmetic filter if and only if the
// character is `$`, `%` or `?`, otherwise it's not a cosmetic
// filter.
// Adguard's style injection: translate to uBO's format.
if ( compileOptions.adgStyleSyntax === true ) {
raw = this.translateAdguardCSSInjectionFilter(raw);
if ( raw === '' ) { return false; }
// Adguard/EasyList style injection: translate to uBO's format.
if ( this.isStyleInjectionFilter(raw) ) {
const translated = this.translateStyleInjectionFilter(raw);
if ( translated === undefined ) { return false; }
raw = translated;
} else if ( compileOptions.adgStyleSyntax === true ) {
return false;
}

// Normalize AdGuard's attribute-based procedural operators.
Expand Down Expand Up @@ -3884,9 +3887,14 @@ class ExtSelectorCompiler {
return true;
}

translateAdguardCSSInjectionFilter(suffix) {
const matches = /^(.*)\s*\{([^}]+)\}\s*$/.exec(suffix);
if ( matches === null ) { return ''; }
isStyleInjectionFilter(selector) {
const len = selector.length;
return len !== 0 && selector.charCodeAt(len-1) === 0x7D /* } */;
}

translateStyleInjectionFilter(raw) {
const matches = /^(.+)\s*\{([^}]+)\}$/.exec(raw);
if ( matches === null ) { return; }
const selector = matches[1].trim();
const style = matches[2].trim();
// Special style directive `remove: true` is converted into a
Expand Down

0 comments on commit ff5fc61

Please sign in to comment.