Creating a Keyword Filter - Struggling with Documentation

Everything about using Adblock Plus on Google Chrome
Post Reply
Shino
Posts: 3
Joined: Fri Aug 28, 2020 4:55 am

Creating a Keyword Filter - Struggling with Documentation

Post by Shino »

Hi all.

I'm stuck. I've spent the last two hours reading and re-reading the ABP documentation, Googling, and experimenting, and I'm still unable to accomplish what I want to do, despite it being implied that what I'm looking for is within ABP's capabilities.

I want to use ABP to block a keyword. Specifically, any specific segment of a webpage that contains specified keyword I want invisible. On any webpage, any domain. This started from me wanting to hide trending topics on Twitter that involve an individual I strongly dislike, but from what I can tell, it should be trivial to block it everywhere, yet it's still not working.

I've tried multiple combinations of the code in the documentation, but despite being fairly well versed in coding, I can't wrap my head around ABP's filter syntax; it just doesn't make logical sense to me. It's not for lack of trying, and I feel like what I'm looking for should be a lot easier than what I've been trying. I'm not including site-specific examples because that would defeat the purpose. I want a simple filter that prevents me from ever seeing the keyword again.

Some examples of what I've tried (among others):
keyword
###keyword
.keyword/
*#?#div:-abp-contains(>div>keyword)
&keyword-
*.*#!#:adp-contains(keyword)

Which special character to use and when just isn't clearly explained, IMO. Since it doesn't seem to be possible for simple words to be added to the filter with no additional fluff, would a "block keyword" list be a difficult feature to implement?

Show me what obvious function I'm missing please. Ideally, I'd like something I can c+p directly into the custom filters list and edit as needed.

Thanks in advance.
User avatar
greiner
ABP Developer
Posts: 899
Joined: Mon Sep 03, 2012 5:29 pm
Location: Cologne, Germany

Re: Creating a Keyword Filter - Struggling with Documentation

Post by greiner »

As an example, for hiding links on adblockplus.org that contain the keyword "Keyword", such as the headline of this forum topic, you can write the following filter:

Code: Select all

adblockplus.org#?#a:-abp-contains(Keyword)
Note that extended element hiding filters (i.e. filters that use ABP-specific CSS selectors such as :-abp-contains()) require specifying one or more domains on which they should be active (e.g. "adblockplus.org"). You cannot use "*" as a placeholder for multiple domains.

In case it helps, here's what the filters you mentioned are doing:
- keyword Block network requests whose URL contains "keyword".
- ###keyword Hide elements with the ID "keyword" on any page.
- .keyword/ Block network requests whose URL contains ".keyword/".
- *#?#div:-abp-contains(>div>keyword) Invalid filter.
- &keyword- Block network requests whose URL contains "&keyword-".
- *.*#!#:adp-contains(keyword) Invalid filter.

Update: I've also created this issue to look into how we can make our filter writing documentation easier to navigate.
Shino
Posts: 3
Joined: Fri Aug 28, 2020 4:55 am

Re: Creating a Keyword Filter - Struggling with Documentation

Post by Shino »

While I'm disappointed that there's no global filter option, that's as close to a perfect answer as I could have hoped for; thanks a ton!

Also, I look forward to reading the updated documentation. I love this extension, but I never really got the hang of it's inner workings and I hope to change that.

Thanks again!
Shino
Posts: 3
Joined: Fri Aug 28, 2020 4:55 am

Re: Creating a Keyword Filter - Struggling with Documentation

Post by Shino »

As an update to anyone trying to figure this out for themselves, I've discovered one last tweak that's helped: spans are apparently separate.

The original element that triggered all this filter hunting wasn't being filtered by the snippet above, though it was working great on the rest of the page. I spent some more time tinkering with the code and help files, and figured out that replacing the "a" with "span" finally eliminated the offending elements; in this case, Twitter trending topics containing the keyword.

Code: Select all

adblockplus.org#?#span:-abp-contains(Keyword)
Post Reply