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.
