メガテック・ボディ

how to filter the discover page using ublock to hide posts with specific words

You are most probably already familiar with uBlock Origin, but you might not be aware that besides blocking ads, trackers, and page elements, you can also create filters to block things which are not always there... such as posts on the discover page.

I will preface that I had to use Claude to do this1, because I don't want to learn another programming language to do something so small. And who the hell actually remembers regex syntax anyways!?

Alright so!

First open your uBlock2 settings, they should be somewhere in your browser extensions menu.

In there should be a tab called My filters. Click that, and below a space for text should appear. If you have blocked items off pages before this could potentially already be populated. Make sure you have Enable my custom filters checked. In Firefox it should be on top of the text box.

Paste my code in there (I will explain it at the bottom):

! bearblog filter for discover page
bearblog.dev##:matches-path(/^\/discover\//) li:has(> div > a:has-text(/(?<![a-z-])word1|word2|word3|(?![a-z-])/i))

Change the word to whatever you want filtered out. If you want different spellings of a specific word, you'll have to enter those manually. So if you want to filter out "dogs", but everyone keeps writing it as "dawg" you should add dogs|dawg|doggo etc.

And now click Apply changes.

Explanation of the components:

The ! bearblog filter for discover page is just a comment to let me know what this thing is, on mine it appears greyed out.

Then bearblog.dev##:matches-path(/^\/discover\//) basically says to assign the filter to the bearblog.dev domain, and turn on the filter on the path of /discover/ and anything after it. So when you click for the second page on the trending page, for example (which would change the url to bearblog.dev/discover/?page=1), it will still remain in effect.

After that the li:has(> div > a:has-text is identifying the html element where the post title exists (which is li). Since I do not want to hide a post by someone who's blog url may contain words from the title the has(> div > a checks only the text inside the first <a></a> element, which usually is the post title.

The regex to look out for specific words looks a bit crazy but it makes sense.

There you go!

One caveat is that the filter removes the whole line from the discover page along with the ranking number. So if the post in #3 was removed, you will see it skipped in the list (#1, #2, #4, etc). I do not mind, but if you have a fix for it, let me know.

If you need any help with this you can ask your local clanker, because I did.

  1. I feel the prick of thy pitchforks already.

  2. I have zero idea if this is the same with uBlock Origin Lite.

#howto #tech #ublock