1 Minute Greasemonkey Guide#
Thu, 17 Jul 2008 15:13:31 +0000
I am a late but fervent convert to Greasemonkey, based on an hour playing with it last night.
- install firebug and learn how to use it. This takes longer than a minute, but we assume you've done it already
- write a javascript file with some funny comments at the top, and call it something.user.js
- In Firefox 3, browse to the file and a popup will, er, pop up allowing you to install the script. In FF2, according to instructions I read there is an extra step here (you need to go to Tools -> Greasemonkey and do something that will probably be fairly obvious)
- Installation will copy the script into your firefox profile directory somewhere (look in the
gm_scripts
subdir). You can edit the file in place thereafter instead of continually reinstalling - to print stuff to the firebug console, use
unsafeWindow.console.log(stuff)
- but be careful, the "unsafe" in the name is not just for show
A few words about the content of the script seem appropriate: it is executed when web pages are loaded (the special comments contain include and exclude directives for you to specify exactly which pages) and references to document
do roughly what you'd expect - so, you can rewrite bits of the DOM tree of other people's websites in nasty brutal "if it breaks you can keep both pieces" hacky ways
Habitable Firefox. Yay
// This is a Greasemonkey user script.
//
// To install, you need Greasemonkey: http://greasemonkey.mozdev.org/
// Then restart Firefox and revisit this script.
//
// ==UserScript==
//
name phpbb killfile
//
namespace http://www.telent.net/
// description brutal script to hide phpbb posts
//
include http://www.example.com/forum/*
// ==/UserScript==
var posts=document.evaluate("//span[@class='name']",document,null, XPathResult.UNORDEREDNODESNAPSHOT_TYPE,null); for(var i=0;i<posts.snapshotLength;i++) { var p=posts.snapshotItem(i); var name=p.firstChild.nextSibling.firstChild.nodeValue; var tr=p.parentNode.parentNode;
if(name=='Moron') { while(tr.firstChild) tr.removeChild(tr.firstChild); var span=document.createElement("span"); span.className="postbody"; var replace=document.createElement("td"); replace.setAttribute("COLSPAN","2"); replace.setAttribute("ALIGN","CENTER"); span.appendChild(document.createTextNode("post hidden")); replace.appendChild(span); tr.appendChild(replace); } }
Probably I should confine the Include directive to viewtopic.php
. Yes, I know a robust solution would include some kind of configuration options to change the list of ignored users, cope with multiple forums etc etc, but that's not the point. Quick and dirty.