Filter with a randomly generated number.

Everything about using Adblock Plus on Google Chrome
Post Reply
ominous
Posts: 1
Joined: Fri Jun 15, 2012 3:20 pm

Filter with a randomly generated number.

Post by ominous »

Hello.

With the help of ABP, I created a filter to hide a specific element from a website:
##p:nth-of-type(9)

the problem is that the number inside the parenthesis is randomly generated. As a result of that, the element reappears whenever I refresh the site.
how can I tweak the filter, so that it will always hide the element regardless of the random number inside the parenthesis?
I understand this can be done with regexp, I searched the forum and read the guides, but I still didnt manage to make it work. :oops:

here is one of the pages from the site:
http://www.aintitcool.com/node/78280

I want to hide the bottom part of the main article with the Amazon movie ads. that whole section can be hidden with the above filter.
the problem is that if I use an odd/even generated number inside the parenthesis, for example by using this: nth-of-type(2n), it will hide almost all the elements in the page, not just the Amazon ads.

so I need the filter to always hide the bottom last, nth-of-type element, regardless of its number.

any help will be welcomed. thank you.
lewisje
Posts: 2743
Joined: Mon Jun 14, 2010 12:07 pm

Re: Filter with a randomly generated number.

Post by lewisje »

There is an :nth-last-of-type, but for your use-case, you should use :last-of-type, as follows:

Code: Select all

aintitcool.com##div.article-content > p:last-of-type
Additionally, you can use some advanced syntax to hide an element based on its children; first here's the ABP way:

Code: Select all

aintitcool.com#?#div.article-content > p:-abp-has(> a[href*="tag=aintitcool"])
Here's the uBlock Origin way, which uses the same syntax as the CSS Selectors 4 drafts:

Code: Select all

aintitcool.com##div.article-content > p:has(> a[href*="tag=aintitcool"])
The last two examples should be more robust against monkeying with the placement of the promotional content; you can make them even more robust by replacing the div.article-content > p bit with * (which means to select any element), at the cost of performance, because then that query will be run against every element, not just p elements that are direct descendants of div elements with the class "article-content"; you do need the "aintitcool.com" specifier before an advanced hiding rule, again for performance reasons.
There's a buzzin' in my brain I really can't explain; I think about it before they make me go to bed.
Post Reply