Procedural cosmetic filters·续
subject:matches-css-before(arg)
Same as :matches-css(...), except that the style will be looked-up for the :before pseudo-class of the subject element.
subject:matches-css-after(arg)
Same as :matches-css(...) except that the style will be looked-up for :after pseudo-class of the subject element.
subject:matches-media(arg)
- Description: Allows limit cosmetic filter by media queries. If is possible will be converted to declarative stylesheet. Preferably should be used as last operator in a procedural cosmetic filter.
- Chainable: Yes.
- subject: Can be a plain CSS selector, or a procedural cosmetic filter.
- arg: Any supported media type by CSSTree.
- Examples:
example.com###target-1 > .target-2:matches-media((min-width: 800px))example.com###target-3 > .target-4:matches-media((min-width: 1920px) and (min-height: 930px)):style(color: red !important)github.com##pre:matches-media(print):style(white-space:pre-line !important;)- disable print scrollbars in PDF
Introduced in uBO 1.43.1b8, feature request #2185.
subject:matches-path(arg)
- Description: Allows to further narrow the specificity according to the path and query of the current document location. Preferably should be used as first operator in a procedural cosmetic filter.
- Chainable: Yes.
- subject: Can be a plain CSS selector, or a procedural cosmetic filter.
- arg: Plain text to be found at any position in the path + query, or a literal regex against which the path + query is tested.
- Examples:
example.com##:matches-path(/shop) p: Will hide allpelements when visitinghttps://example.com/shop/stuff, but not when visitinghttps://example.com/or any other page onexample.comwhich has no instance of/shopin the path part of the URL. To only match the main page but not any of the subpages, use:example.com##:matches-path(/^/$/) p
Introduced in uBO 1.37.3b13, feature request #1690.
This is a all-or-nothing passthrough operator, which on/off behavior is dictated by whether the argument match the path of the current location. The argument can be either plain text to be found at any position in the path, or a literal Regular Expression against which the path is tested.
Whereas cosmetic filters can be made specific to whole domain, the new :matches-path() operator allows to further narrow the specificity according to the path of the current document location.
Typically this procedural operator is used as first operator in a procedural cosmetic filter, so as to ensure that no further matching work is performed should there be no match against the current path of the current document location.
subject:matches-prop(arg)
- Description: Allows to select an element by a property name (or chain of properties), and optionally the property value.
- Chainable: Yes
subject: Can be a plain CSS selector, or a procedural cosmetic filter.arg: A declaration in the formchain=value,chain="value", orchain=/regex/, wherechainis a dot-separated string for the target property, andvalueis the optional property value to match.valuecan be literal text or literal regular expression. When novalueis declared, the operator only tests for the presence of the target property.- Example:
example.org##div:matches-prop(imanad)example.org##img:matches-prop(naturalWidth=160)
subject:min-text-length(n)
- Description: DOM elements whose text length is greater than or equal to
nwill be selected. - Chainable: Yes.
- subject: Can be a plain CSS selector, or a procedural cosmetic filter.
- n: positive number, minimal text length of the subject DOM element.
- Examples:
- Regular expression based filter:
quoka.de##^script:has-text(/[\w\W]{35000}/)can be rewritten as:quoka.de##^script:min-text-length(35000).
- Regular expression based filter:
Introduced in uBO 1.20.1b2 As a result of internal discussion<sup>[1]</sup> with filter list maintainers. The original rationale for such procedural cosmetic operator is to be able to remove inline script elements according to a minimum text length using HTML filtering.
<sub>[1] https://github.com/orgs/uBlockOrigin/teams/ublock-filters-volunteers/discussions/194?from_comment=65</sub>
subject:not(arg)
- Description: Select element subject if and only if the result of evaluating arg is exactly zero elements.
- Chainable: Yes.
- subject: Can be a plain CSS selector, or a procedural cosmetic filter.
- arg: A procedural cosmetic filter, which is evaluated in the context of the subject element.
Introduced in uBO 1.17.5b9 to increase compatibility with AdGuard filter syntax.
Use to negate other procedural selectors. For example :not(:has(.foo)) will match if there are no descendant matching .foo.
Note that if arg is valid CSS selector, uBO will not consider the :not operator to be a procedural one, it will rather consider the operator as being part of a CSS selector. Thus this ensures compatibility with the existing
CSS :not(...) pseudo-class.
subject:others()
Experimental.
- Description: Target all elements outside than the currently selected set of elements.
- Chainable: Yes.
- subject: Can be a plain CSS selector, or a procedural cosmetic filter.
- Examples:
twitter.com##:matches-path(/^/home/) [data-testid="primaryColumn"]:others()nature.com##:matches-path(/^/articles//) :is(.c-breadcrumbs,.c-article-main-column):others()
Introduced in uBO 1.41.1b2
For any element feeding into others(), the resultset of the others() operator will include everything else except:
- the descendants of a subject element
- the ancestors of a subject element
The resultset will contains the siblings of a subject element except when those siblings are either a descendant or ancestor of another subject element.
Though this operator is unlikely to be used in default lists, it opens the door to create specialized filter lists which purpose is some sort of "reader mode", where everything else than a selected set of elements are hidden from view.
Related discussion: - https://www.reddit.com/r/uBlockOrigin/comments/slyjzp/
subject:upward(arg)
- Description: lookup the ancestor relative to the currently selected node.
- Chainable: Yes.
- subject: Can be a plain CSS selector, or a procedural cosmetic filter.
- arg:
- Positive number >= 1 and < 256, distance from the currently selected node.
- A valid plain CSS selector.
- Examples:
- Existing filter:
fastbay.org##.detLink:has-text(VPN):xpath(../../..)can be rewritten asfastbay.org##.detLink:has-text(VPN):upward(3) gorhill.github.io###pcf #a19 b:upward(2)gorhill.github.io###pcf #a20 b:upward(.fail)
- Existing filter:
Introduced in uBO 1.25.3b0. Evolution of :nth-ancestor(n) selector.
See also: :upward() vs :has()
subject:watch-attr(arg)
Experimental.
- Description: Pass-through filter used to modify behavior of the procedural cosmetic filter engine by forcing re-evaluation when one or more attribute changes on the matching elements.
- Chainable: Yes.
- subject: Can be a plain CSS selector, or a procedural cosmetic filter.
- arg: comma-separated list of attribute names. No argument means watch changes of any one attribute.
Example:
- Test case to detect id changes using filter ameshkov.github.io###testdiv:watch-attr(id):has(p)
- example.com##.j-mini-player[class]:watch-attr(class):remove-attr(class)
Introduced in uBO 1.17.5rc3
Solves uBlockOrigin/uBlock-issues#341 (comment) (overlay dialog used for two purposes, differ only by class name in child node).
By default hiding by procedural filters is reevaluated only when nodes in sub-tree are added or removed - uBO does not watch for attribute changes for performance reasons. This filter instructs uBO procedural filtering engine to watch for changes in specific attributes.
subject:xpath(arg)
- Description: Create a new set of elements by evaluating an XPath expression using subject as the context node (optional) and arg as the expression.
- Chainable: Yes.
- subject: Optional. Can be a plain CSS selector, or a procedural cosmetic filter.
- arg: A valid XPath expression.
- Examples:
facebook.com##:xpath(//div[@id="stream_pagelet"]//div[starts-with(@id,"hyperfeed_story_id_")][.//h6//span/text()="People You May Know"])
The :xpath(...) operator is different than other operators. Whereas all other operators are used to filter down a resultset of elements, the :xpath(...) operator can be used both to create a new resultset or filter down an existing one. For this reason, subject is optional. For example, an :xpath(...) operator could be used to create a new resultset consisting of all ancestors elements of a subject element, something not otherwise possible with either plain CSS selectors or other procedural operators.
