Why YSK: Certain topics are stressful and tend to spread all over the site, including to unrelated communities. Blocking communities can be overkill and ineffective, and likewise for blocking individual users.

To do so, open up the uBlock Origin dashboard, go to the ‘My filters’ tab, and add this filter:

lemmy.world##article.row:has-text(/word1|word2|word3|word4/i)

For example:

lemmy.world##article.row:has-text(/Trump|Elon|Musk|nazi/i)

Then apply the changes and reload any open tabs, and all posts which contain any of your filtered words will simply not show up.

You’ll have to change “lemmy.world” at the start to whatever your actual instance is. You can filter as many or as few words as you want, just keep the / at the start, the /i at the end, and separate words with | pipes. What’s actually being filtered is a case-insensitive regex, if you want to get fancy with it.

Here are equivalent filters for reddit and Ars Technica:

reddit.com##div.thing[data-context="listing"]:has-text(/word1|word2|word3|word4/i)
arstechnica.com##article:has-text(/word1|word2|word3|word4/i)

As a disclaimer, I made these myself, and I’m not particularly familiar with creating uBlock Origin filters. There may be better ways to do this. Also the reddit one is specific to old.reddit.com, and the lemmy filter is made to work with the default lemmy.world web UI and may not work on other UIs without tinkering.

Yes, I know I’m just hiding my head in the sand.

  • jumperalex@lemmy.world
    link
    fedilink
    English
    arrow-up
    3
    ·
    1 day ago

    How would one implement these filters but EXCLUDE certain things … like say … filter anything with “MAGA” but allow it if there’s also mention of “Leopards” is still allowed? :)

    • zkfcfbzr@lemmy.worldOP
      link
      fedilink
      English
      arrow-up
      3
      ·
      1 day ago
      lemmy.world##article.row:has-text(/word1|word2|word3/i):not(:has-text(/word4|word5|word6/i))
      

      or

      lemmy.world##article.row:has-text(/maga/i):not(:has-text(/leopard/i))
      

      will do what you want - it’ll block any posts which contain words from the first regex, unless it also has some words from the second regex

      • dmtalon@infosec.pub
        link
        fedilink
        arrow-up
        1
        ·
        edit-2
        10 hours ago

        So, adding the not clause works but only if the leopard is within the title row I believe. I can go to the leopards ate my face and see posts, but those with the block words are still being filtered. Since you’re now our IT support for UBO and Regex do you by chance know if it’s possible to connect the title and community rows into a UBO filter for the :not part?

        • zkfcfbzr@lemmy.worldOP
          link
          fedilink
          English
          arrow-up
          2
          ·
          7 hours ago

          I’m not sure I follow - the filter seems to work as-is to me. It allows posts on both the front page and the !leopardsatemyface@lemmy.world to bypass the filter for me.

          To be clear, it’s not only applying to the title row - the article tag it targets contains the entire post as it appears in the post feed, including the title, community name, the person who submitted it, the timestamp, etc. So if anything there contains a filtered or whitelisted word it should trigger the filter.

          I wouldn’t have necessarily expected the whitelist filter to work directly on the leopards community page, since posts on community feeds don’t include the community name, but it works anyways because, it seems, there’s a hidden mod option in the HTML with the community name in it: <div class="modal-body text-center align-middle text-body">Are you sure you want to transfer leopardsatemyface@lemmy.world to TheBat@lemmy.world?</div>

          • dmtalon@infosec.pub
            link
            fedilink
            arrow-up
            1
            ·
            7 hours ago

            I did not do extensive testing, but what I did was directly visit the leopards at my face community and could see there were articles being blocked within there. This filter leaves the separator lines of the posts that have been removed, and I was surprised to see articles blocked when viewing that community directly. Maybe I just messed up my regex, but I wanted to unblock anything with leopard/leopards in it even if it wasn’t within that specific community just in case

            infosec.pub##article.row:has-text(/Trump|Elon|Musk|nazi|TikTok/i):not(:has-text(/leopard(s)?|schadenfreude|find out/i))
            
            • zkfcfbzr@lemmy.worldOP
              link
              fedilink
              English
              arrow-up
              1
              ·
              5 hours ago

              Actually it seems to be a difference based on our instances - if I look at the community from infosec.pub then the bit of HTML I quoted above with the mod option isn’t present, and there’s no ‘leopard’, hidden or explicit, for the whitelist filter to find.

              As a note, the (s)? on your leopard isn’t needed - just ‘leopard’ will already match the ‘leopard’ part of ‘leopards’

              I don’t know how to fix this currently, but I’ll test out a bit more later to see if I can find anything that works well

                • zkfcfbzr@lemmy.worldOP
                  link
                  fedilink
                  English
                  arrow-up
                  1
                  ·
                  39 minutes ago

                  Hey! I’m pretty sure this one will work:

                  infosec.pub##:not(a.community-link:matches-attr(title=/.*?leopard.*?/i)) article.row:has-text(/Trump|Elon|Musk|nazi/i):not(:has-text(/leopard/i))
                  

                  Where now we have three filters. If the community name matches the first regex, then nothing at all will be filtered out - and then the other two work the same as before. So any post that matches the blacklist regex will be filtered out unless it also matches the whitelist regex.

                  I chose to make the first regex /.*?leopard.*?/i because my thinking is you may want to just copy/paste the other whitelist filter there for simplicity, but it might make more sense to do it like the others, like /leopardsatemyface|second community|third community|etc/i. The “title” of a community for the purpose of this filter should be whatever appears after /c/ in the URL, not counting the @lemmy.world (or whatever instance) part.