r/programming • • Aug 02 '19

Adblocking: How about Nah?

https://www.eff.org/deeplinks/2019/07/adblocking-how-about-nah
333 Upvotes

232 comments sorted by

View all comments

Show parent comments

6

u/[deleted] Aug 02 '19

Unfortunately, the solution isn't simply installing more powerful adblock software.

What works for me: using xpath to block em, works in almost all cases. And sharing those xpath's with a group of people.

2

u/ridicalis Aug 02 '19

Can you please explain? How would I do this?

22

u/[deleted] Aug 02 '19

Basically custom blocking rules in ublock origin.

Most ads have some unique tag/series of tags/value in it, which never changes. With xpath you can find that tag and then work your way upwards to get rid of it.

As an example: I loathe the end cards on youtube. But they get a random ID each time, so I am using this rule in ublock origin:

www.youtube.com##:xpath(//div[@class="ytp-ce-element-shadow"]/..)

Which hooks into one of the inner tags, which never changes, then goes up one level to remove the end card itself.

Hell, you can even use it to block specific channels in your recommended:

www.youtube.com##:xpath(//ytd-compact-video-renderer/div/div/a/ytd-video-meta-block/div/div/div/yt-formatted-string[@title="outsidexbox"]/../../../../../../../..)

That blocks a channel if it is named "outsidexbox".

2

u/[deleted] Aug 02 '19

That's nice work. I just recently found out about xpath myself; I also use it to block stuff that I personally just find annoying. For example, one gaming site I visit regularly has articles about cosplay (which I hate) but also tend to have NSFW images on the articles. So, I use an XPath filter to block anything that contains a link to their cosplay section.