Blocked User Eraser Firefox Plugin

Edit 15/3: Noticed that the class name of blocked comments changes, so have updated. In case you're wondering why it doesn't work anymore.

I noticed recently that if you block a user, the site still shows stubs from their comments, which I found very annoying, as I do not wish to be continually reminded of their existence. So I wrote a very simple plugin to remove those stubs. This post is in case anyone else was looking for something similar, saves them having to write it too.

It is at https://addons.mozilla.org/firefox/addon/ozbargain-blocked-u… and you can install it from there. Or you can do the following.

In the same folder:

  • Make a file called manifest.json
  • Make a folder called icons
  • Make a file called eraser.js

In manifest.json paste the following:

{
  "manifest_version": 2,
  "name": "Eraser",
  "version": "1.0",
  "description": "Removes blocked user comment stubs",
  "icons": {
    "48": "icons/border-48.png"
  },
  "content_scripts": [
    {
      "matches": ["*://*.ozbargain.com.au/*"],
      "js": ["eraser.js"]
    }
  ]
}

In eraser.js paste the following:

function getElementsByXPath(xpath, parent)
{
    let results = [];
    let query = document.evaluate(xpath, parent || document,
        null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
    for (let i = 0, length = query.snapshotLength; i < length; ++i) {
        results.push(query.snapshotItem(i));
    }
    return results;
}
let items3 = getElementsByXPath( '//body//div[@id="main"]//div[@class="wrap wrapsb1"]//div[@class="wrap2"]//div[@id="content"]//ul[@class="comment level0"]//li//ul[@class="comment level1"]//li//ul[@class="comment level2"]//li//ul[@class="comment level3"]//li//div[@class="comment-wrap"]//div[@class="comment hidden blocked"]');
let items2 = getElementsByXPath( '//body//div[@id="main"]//div[@class="wrap wrapsb1"]//div[@class="wrap2"]//div[@id="content"]//ul[@class="comment level0"]//li//ul[@class="comment level1"]//li//ul[@class="comment level2"]//li//div[@class="comment-wrap"]//div[@class="comment hidden  blocked"]');
let items1 = getElementsByXPath( '//body//div[@id="main"]//div[@class="wrap wrapsb1"]//div[@class="wrap2"]//div[@id="content"]//ul[@class="comment level0"]//li//ul[@class="comment level1"]//li//div[@class="comment-wrap"]//div[@class="comment hidden  blocked"]');
let items0 = getElementsByXPath( '//body//div[@id="main"]//div[@class="wrap wrapsb1"]//div[@class="wrap2"]//div[@id="content"]//ul[@class="comment level0"]//li//div[@class="comment-wrap"]//div[@class="comment hidden  blocked"]');
let items = items0.concat(items1).concat(items2).concat(items3);
for(i = 0; items.length; i++) {
  items[i].parentNode.style.display='none';
}

Find any random 48 by 48 pixel image and put it in the icons folder, and name it "border-48.png".

Open about:debugging from the URL bar in Firefox

Click Load Temporary Add-on and select manifest.json

The plugin should now work until you restart Firefox. You can probably copy & paste to make plugins for other browsers too. Anyone is welcome to take this and use it for whatever purpose they see fit.

P.S. Thanks Scotty for the code tags

Comments

  • +2

    Meow?

    • +3

      Wonder if the blocker also blocks showing who upvoted certain comments? OP must really hate someone haha.

  • +3

    who're you trying to erase

  • Why do I have to "Sign in to continue to Add-ons"?

    • If you don't want to do that you can add it manually. I'm not really sure how the system works

    • +2
      • Thanks! Fixed.

        • +1

          Thanks QuantumCat. Wish I could block more than 50 commentators.

          • @bongom: Would you like a manual blocker? Eg putting a list of usernames in a text file and having it remove their comments? Not sure if it would make pages load slowly or not though.

  • I find the stub annoying too but at least it provides some context to comment flow.

  • Blocking out their username seems to be a standard feature on the site now.

    • Yeah I just noticed that

      If you are listening Scotty, I'd prefer a discreet button at the top or bottom of the page that says Show comments from blocked users (or Hide if they are currently being shown), and they are totally hidden (no stub) when hidden.

      Thanks for removing the name, though!!

Login or Join to leave a comment