51

Is it possible to write a custom filter rule so that any div, span or p and its children are hidden when there is a specific word in the text part, i.e. Trump?

For example, I have this structure

<div>
  <a class="..." href="...">Donald Trump said blablabla.</a>
</div>

I tried this, but it has no effect:

##div>a:has-text(Trump)
DavidPostill
  • 162,382

3 Answers3

55

Try ##div>a:has-text(/Trump/)

Arthur
  • 659
15

:has-text() is a procedural cosmetic filter. Those "must always be specific, i.e. prefixed with the hostname of the site(s) on which they are meant to apply."

Procedural cosmetic filters are powerful but to be avoided if possible as they can slow down site loading (JavaScript has to be inserted and visit lots of nodes).

If you still want it, it should look like this:

example.com,domain.com,anotherexample.com##div>a:has-text(Trump)

You can change that behaviour so a non-specific procedural cosmetic filter like ##div>a:has-text(Trump) will work, but it is absolutely not recommended. It will slow down your browser on every page and there's the possibility that errors in external filterlists will go free-turning and produce lots of false positives / overblocking.

You can find that option buried in

  1. uBO Dashboard
  2. Settings
  3. Check "I am an advanced user"
  4. Read and understand the warnings
  5. Click the gears
  6. Change "allowGenericProceduralFilters" to true
  7. Click "Apply changes"

p.s.: Forward slashes like :has-text(/Target words/)are not needed. If you use them, the expression inside will be evaluated as RegEx which will cause even more workload.

FatBat
  • 296
  • 3
  • 6
2

It seems has-text selector only works when a top level domain is given. So the following works, for example, but only on the Guardian website:

theguardian.com##.fc-item__container:has-text(Trump)