From 72bb70056843024b1a31fe1ab9c90bd4e8260ba2 Mon Sep 17 00:00:00 2001 From: Raymond Hill Date: Sat, 7 Mar 2020 14:25:06 -0500 Subject: [PATCH] Add procedural cosmetic operators remove() and upward() *** New procedural cosmetic operator: `:remove()` Related issue: - https://github.com/gorhill/uBlock/issues/2252 The purpose is to outright remove elements from the DOM tree. Since `:remove()` is an "action" operator, it must only be used as a trailing operator (just like the `:style()` operator). AdGuard's cosmetic filter syntax `{ remove: true; }` will be converted to uBO's `:remove()` operator internally. *** New procedural cosmetic operator: `:upward(...)` The purpose is to lookup an ancestor element. When used with an integer argument, it is synonym of `:nth-ancestor()`, which will be deprecated and which will no longer be supported once no longer used in mainstream filter lists. Filter lists maintainers must only use `:upward(int)` instead of `:nth-ancestor(int)` once the new operator become available in all stable releases of uBO. `:upward()` can also accept a CSS selector as argument, in which case the nearest ancestor which matches the CSS selector will be selected. --- .../css-selector-based-cosmetic-filters.html | 150 ++++++++++++ docs/tests/index.html | 8 +- docs/tests/procedural-cosmetic-filters.html | 15 ++ docs/tests/procedural-html-filters.html | 10 + platform/chromium/vapi-usercss.pseudo.js | 2 +- src/js/contentscript.js | 116 +++++---- src/js/cosmetic-filtering.js | 2 +- src/js/html-filtering.js | 75 +++--- src/js/scriptlets/cosmetic-logger.js | 8 +- src/js/scriptlets/element-picker.js | 6 +- src/js/static-ext-filtering.js | 231 ++++++++++-------- 11 files changed, 438 insertions(+), 185 deletions(-) create mode 100644 docs/tests/css-selector-based-cosmetic-filters.html diff --git a/docs/tests/css-selector-based-cosmetic-filters.html b/docs/tests/css-selector-based-cosmetic-filters.html new file mode 100644 index 000000000..9c1998121 --- /dev/null +++ b/docs/tests/css-selector-based-cosmetic-filters.html @@ -0,0 +1,150 @@ + + + + + +CSS selector-based cosmetic filters + + + +

CSS selector-based cosmetic filters

+

Back +

+

Filters

+
+ +

Tests

+
+ +
+
+ #ccf #a1 .fail +
+ +
+
+ #ccf #a2 .fail:not(.a2) +
+ +
+
+ #ccf #a3 .fail +
+ +
+
+ #ccf #a4 .fail:not(.a4) +
+ +
+
+ #ccf #a5 .fail:style(visibility: hidden) +
+ +
+
+ #ccf #a6 .fail-pseudo::before +
+ +
+
+ #ccf #a7 .fail-pseudo::before +
+ +
+
+ #ccf #a8 .fail-pseudo::before:style(visibility: hidden) +
+ +
+ + + + diff --git a/docs/tests/index.html b/docs/tests/index.html index fec110a96..b0558c156 100644 --- a/docs/tests/index.html +++ b/docs/tests/index.html @@ -9,12 +9,14 @@

uBlock Origin tests

Some of the pages below are hosted on raw.githack.com in order to ensure some of the secondary resources can be properly loaded (specifically, the WebAssembly modules, as they require to be loaded using same-origin policy).

diff --git a/docs/tests/procedural-cosmetic-filters.html b/docs/tests/procedural-cosmetic-filters.html index 608d24986..714ea1acd 100644 --- a/docs/tests/procedural-cosmetic-filters.html +++ b/docs/tests/procedural-cosmetic-filters.html @@ -167,6 +167,21 @@ #pcf #a17 .fail:has(~ a:has(b)) +
+
+ #pcf #a18 .fail:remove() +
+ +
+
+ #pcf #a19 b:upward(2) +
+ +
+
+ #pcf #a20 b:upward(.fail) +
+