Skip to content

Instantly share code, notes, and snippets.

@stefanschmidt
Last active May 5, 2023 11:31
Show Gist options
  • Save stefanschmidt/ccf366713bfda8f245f9b38720beb5bb to your computer and use it in GitHub Desktop.
Save stefanschmidt/ccf366713bfda8f245f9b38720beb5bb to your computer and use it in GitHub Desktop.
Filter rule for matching a text in a div tag with an apostrophe/quote/quotation mark with uBlock Origin

Test with Chrome 112.0.5615.137 and uBlock Origin 1.49.2

Doesn't work (hides all divs)

www.google.com##div:has-text("It looks like there aren't many great matches for your search")
www.google.com##div:has-text(/It looks like there aren\'t many great matches for your search/)

Works

Use a more specific filter rule

Possibly because it narrows down the number of divs to consider.

www.google.com##div[role="heading"]:has-text("It looks like there aren't many great matches for your search")

Use a regular expression

Escape the apostrophe/quote/quotation mark and add markers for beginning ^ and end $ of text.

www.google.com##div:has-text(/^It looks like there aren\'t many great matches for your search$/)

Use an xpath expression

www.google.com##div:xpath(//div[contains(text(), "It looks like there aren't many great matches for your search")])

Complete filter rule using upward operator

Fairly verbose, but not affected by changes of class or id names. The upward operator is more concise alternative to using the xpath operator with the ancestor axis (e.g. xpath(ancestor::div[data-async-context])).

www.google.com##div:has-text(/^It looks like there aren\'t many great matches for your search$/):upward(div[data-async-context]) > div:nth-child(1)

Complete filter rule using id attribute

Very simple, but possibly less robust.

www.google.com##div#rso > div:nth-child(1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment