From ec56165d0d36ab91fba7d5cf44a4552d19fefdd5 Mon Sep 17 00:00:00 2001 From: Raymond Hill Date: Tue, 6 Mar 2018 09:09:53 -0500 Subject: [PATCH] new `script:inject` syntax, use only when next release is *very* widespread --- src/js/cosmetic-filtering.js | 1 - src/js/static-ext-filtering.js | 14 +++++++++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/js/cosmetic-filtering.js b/src/js/cosmetic-filtering.js index d634b93a1..9fb2d762d 100644 --- a/src/js/cosmetic-filtering.js +++ b/src/js/cosmetic-filtering.js @@ -393,7 +393,6 @@ var FilterContainer = function() { '^', '(?:', [ - 'script:contains', '.+?:has', '.+?:has-text', '.+?:if', diff --git a/src/js/static-ext-filtering.js b/src/js/static-ext-filtering.js index 6d90a03b8..6c334dd6d 100644 --- a/src/js/static-ext-filtering.js +++ b/src/js/static-ext-filtering.js @@ -37,6 +37,7 @@ - cosmetic filtering (aka "element hiding" in Adblock Plus) - scriptlet injection: selector starts with `script:inject` + - New shorter syntax (1.15.12): `example.com##+js(bab-defuser.js)` - html filtering: selector starts with `^` Depending on the specialized filtering engine, field 1 may or may not be @@ -655,10 +656,21 @@ } } + var c0 = suffix.charCodeAt(0); + + // New shorter syntax for scriptlet injection engine. + if ( c0 === 0x2B /* '+' */ && suffix.startsWith('+js') ) { + // Convert to deprecated syntax for now. Once 1.15.12 is + // widespread, `+js` form will be the official syntax. + parsed.suffix = 'script:inject' + parsed.suffix.slice(3); + µb.scriptletFilteringEngine.compile(parsed, writer); + return true; + } + // HTML filtering engine. // TODO: evaluate converting Adguard's `$$` syntax into uBO's HTML // filtering syntax. - if ( suffix.charCodeAt(0) === 0x5E /* '^' */ ) { + if ( c0 === 0x5E /* '^' */ ) { µb.htmlFilteringEngine.compile(parsed, writer); return true; }