Basically, what it does is to modify webpages on-the-fly as you load them - using JavaScript. Many times I guess people use it to get rid of nasty ads and so forth. There are plenty of other add-ons able to do that - like removing a specific element each time, which doesn't require any coding. What fun is that?
Nonetheless, my first Greasemonkey-script does just that - removes an ad. But for the site in question - www.di.se (all in Swedish) - it isn't as easy as removing an element. The site is divided into 3 rows using a frameset that looks like this:
As you maybe can tell, removing the second frame (which contains the 210px ad) doesn't cut it, because the third frame (content) will now take it's place.
<frameset frameborder="no" framespacing="0" rows="0,210,*">
<frame class="noprint" frameborder="no" framespacing="0" name="historyFrame" noresize="" scrolling="no" src=""></frame>
<frame class="noprint" frameborder="no" framespacing="0" name="headerFrame" noresize="" scrolling="no" src=""></frame>
<frame class="" frameborder="no" framespacing="0" name="contentFrame" noresize="" scrolling="auto" src=""></frame>
</frameset>
This is where Greasemonkey comes to rescue! Creating the following script tells Greasemonkey to change to rows-attribute of the frameset to hide the ad frame, allowing the content frame to use all available space:
// ==UserScript== // @name Clean up di.se // @namespace http://www.technowobble.com // @description Removes the top add from www.di.se // @include http://www.di.se/ // @grant none // ==/UserScript== var frameset = document.getElementsByTagName('frameset'); if (frameset[0]) { frameset[0].rows="0,0,*"; }It will only be applied to http://www.di.se/ (notice the trailing slash which seems to be required) and I will never have to see the ad again. Sweet. But what more can you do with it? Anything, from removing ads, changing look & feel etc, to do automatic user interface testing or exploiting vulnerabilities, I guess?
> But what more can you do with it?
ReplyDeleteCheck out userscripts.org
http://userscripts.org/
It's the unofficial site for greasemonkey. As far as I am concerned - it should be called greasemonkey.org