Nintendo Wii forums Forum for writers phpBB mods Essays on copyright Dating advice Narnia forums

GreaseMonkey script for Digg friends stuff

So almost immediately after posting my previous GreaseMonkey script, I was reading some Digg comments and noticed someone asking for some new user preferences on Digg – in particular, he wanted Digg to turn off all the alerts and boxes for the friends list.  I thought it was overkill to depend upon Digg for that, when a simple JavaScript would change it.  However, as with my previous script, it wasn't as easy as I expected.

The problem is that Digg doesn't put their friends list boxes into named DIV tags.  So I can't just easily getElementById and then set the display to none.  Instead, I needed something like getElementByClass, which doesn't exist.  So I went through the GreaseMonkey docs, found out how to use document.evaluate() in a way that hunts for attributes of a tag (thus, the equivalent of getElementByClass), and then finally I looped through the resulting objects, and found the one that had the text about the friends list.  Yay!

So here is what I came up with.  The first few lines are just copied & modified from Dive Into Greasemonkey.

var allDivs, thisDiv;
allDivs = document.evaluate(
"//div[@class='side-container']",
document,
null,
XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE,
null
);
for (var i = 0; i < allDivs.snapshotLength; i++) {
thisDiv = allDivs.snapshotItem(i);
if (thisDiv.innerHTML.match(/Activity in 48hr<\/h2>/) ||
thisDiv.innerHTML.match(/<h2>Add Your Friends/)) {
thisDiv.style.display = "none";
}
}

If you would like to stop the display of the friend box and the "so-and-so invited so-and-so" text, you can install this script into your GreaseMonkey-compatible browser.  Have fun.

Navigate

« GreaseMonkey script for Bioware forums | Main | Giving Movable Type WYSIWYG Editing »

Nav by tag: greasemonkey
« GreaseMonkey script for Bioware forums | Main | Fixing the City of Palo Alto site »
Nav by tag: tech
« GreaseMonkey script for Bioware forums | Main | Giving Movable Type WYSIWYG Editing »
Bookmark It! Technorati del.icio.us Netvouz DZone ThisNext Wists blinkbits BlinkList blogmarks blogtercimlap Blue Dot Bumpzee co.mments connotea DotNetKicks Fark feedmelinks Fleck Furl Gwar Haohao Hemidemi IndiaGram IndianPad Internetmedia kick.ie LinkaGoGo Linkter Ma.gnolia MyShare Netscape NewsVine PlugIM PopCurrent ppnow RawSugar Reddit Shadows Simpy Slashdot Smarking Spurl Webride YahooMyWeb
TrackBack

TrackBack URL for this entry:
http://www.outshine.com/cgi-bin/outshine/trackback.cgi/23

Post a comment

Verification (needed to reduce spam):