xkcd Greasemonkey script
Nick put me on to xkcd.com a while ago. One thing that’s annoyed me about it for quite some time is that to read some of the joke you have to hover over the image to read the title attribute; and if that attribute’s value is too long you end up having to view the source to read it. Boring.
Greasemonkey to the rescue! I heard about this extension for firefox before but had no need of it, it allows you to write some javascript that will get executed for a particular website. Cool.
Before
After
Script (Download xkcd.com comic title greasemonkey script)
// ==UserScript==
// @name xkcd comic title
// @namespace http://xkcd.com
// @include http://*xkcd.com/*
// ==/UserScript==
var arrObjImages = document.getElementsByTagName(”img”);
var iImg;
for(iImg = 0; iImg < arrObjImages.length; iImg++){
var objImage = arrObjImages[iImg];
var sImgTitle = objImage.getAttribute("title");
if(sImgTitle != null && sImgTitle.length > 0){
//image title
objImage.parentNode.insertBefore(document.createTextNode(sImgTitle),
objImage.nextSibling);
//two line breaks
objImage.parentNode.insertBefore(document.createElement(”br”), objImage.nextSibling);
objImage.parentNode.insertBefore(document.createElement(”br”), objImage.nextSibling);
};//end if
};//end for
Dive into Greasemonkey (Sounds a perverted don’t you think?)
Start Slide Show with PicLens Lite
By default, the above script does not work. Probably because of the include line. It should be this:
// @include http://*xkcd.com/*
Notice that I removed the trailing slash.
Also, by naming the script as it is, it makes it tougher to install. Greasemonkey will intercept any file that ends with .user.js (dot user dot js) but the above has to be done manually.
The script did work when you were looking at older comics (e.g. http://xkcd.com/1/) but not as you’ve pointed out for the current comic on the home page, didn’t consider this at the time and hadn’t realised.
Didn’t know about the .user.js interception and offering to install the script, that’s cool.
I’ve updated the script with both of your suggestions, thanks Brandon.