Skip to content

Instantly share code, notes, and snippets.

@beastaugh
Created September 27, 2008 10:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save beastaugh/13311 to your computer and use it in GitHub Desktop.
Save beastaugh/13311 to your computer and use it in GitHub Desktop.
javascript:(function(){var e="http://imgs.xkcd.com/comics/",t=document.getElementsByTagName("img"),n=t.length;while(n--){if(t[n].src.substring(0,e.length)===e){alert(t[n].title);return;}}})();
/**
* Run this on any http://xkcd.com/ comic page to pop up an alert with the comic title.
*
* Code inspired by this article and bookmarklet:
* http://www.blendedtechnologies.com/read-xkcd-on-the-iphone-finally/223
*
* Also see this Hacker News posting: http://news.ycombinator.com/item?id=316621
*
* In order to run it as a bookmarklet, the code needs to be prefixed with javascript:
* You should probably also run it through something to remove comments and whitespace.
*/
(function() {
var comics_url = 'http://imgs.xkcd.com/comics/';
var imgs = document.getElementsByTagName('img');
var i = imgs.length;
while (i--) {
if (imgs[i].src.substring(0, comics_url.length) === comics_url) {
alert(imgs[i].title);
return;
}
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment