Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Building an add-on to hide a <div> block on an HTML page

There's a webpage with something annoying on it which I'd like to hide every time I visit it. I thought a good way to do this would be to make an add-on for Firefox.

I've never done this before, and came across the web-based Firefox add-on builder. I'm not too sure where to go from here though. I know it should be quite easy to do this though. I suppose all I need to do is check if a block with a certain id is used on a website, and if it is, then delete/hide it from my view.

Is that the best way to do about this? If not, what do you suggest? If so, can you give me any tips to help me accomplish this?

like image 951
capcom Avatar asked Sep 11 '12 00:09

capcom


People also ask

How do I hide a div block in HTML?

To hide an element, set the style display property to “none”. document. getElementById("element"). style.

How do I hide a div on my website?

Use display none on the element eighter in HTML, or in CSS files. Attribute hidden is also helpful.

How do you make a element hidden in HTML?

Completely hiding elements can be done in 3 ways: via the CSS property display , e.g. display: none; via the CSS property visibility , e.g. visibility: hidden; via the HTML5 attribute hidden , e.g. <span hidden>

How do I hide content inside a div?

You can hide an element in CSS using the CSS properties display: none or visibility: hidden . display: none removes the entire element from the page and mat affect the layout of the page. visibility: hidden hides the element while keeping the space the same.


2 Answers

Right, I got it:

Using just a standalone Firefox Add-On use the following code:

exports.main = function() {

    var pageMod = require("page-mod");
        pageMod.PageMod({
        include: "*.ca",
        contentScriptWhen: 'end',
        contentScript: 'document.getElementById("DIVID").style.visibility="hidden";'
    });
};

Just replace DIVID with whatever you want.

Similarly, in Greasemonkey, just add this to the script:

document.getElementById('DIVID').style.visibility='hidden';

The only reason I didn't want to use Greasemonkey is that it isn't as easy to share. But it's convenience can't be beat!

like image 160
capcom Avatar answered Sep 26 '22 17:09

capcom


  1. Install the latest FF
  2. Install the latest AdBlock Plus
  3. Go to the website right click on specific element and then Inspect Element(Q)
  4. Right bottom corner there is Hide with ABP(AdBlock Plus) button, click on it, then Add Element Hiding Rule
like image 42
a clever name Avatar answered Sep 22 '22 17:09

a clever name