Skip to content

Instantly share code, notes, and snippets.

@jeffalexander
Last active December 12, 2015 07:19
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jeffalexander/4735750 to your computer and use it in GitHub Desktop.
Save jeffalexander/4735750 to your computer and use it in GitHub Desktop.
XKCD Bookmarklet that on click 1) takes you to xkcd.com then click 2) inserts the image title under comic, scrolling into view if needed, and click 3) takes you to explainxkcd.com.
javascript:
cd=document.getElementById('comic');
if(cd) {
if(cd.childElementCount==2) {
window.location='http://explainxkcd.com';
} else {
p=document.createElement('p');
i=cd.children[0];
if(i.tagName=='A') {
i=i.children[0];
}
p.innerText='Title: '+i.title;
cd.insertBefore(p, null);
p.scrollIntoView(false);
}
} else {
window.location='http://xkcd.com';
}
To use, copy and paste into an existing bookmark's URL.
Bugs:
For chrome users this (and any other bookmarklet) won't work on the New Tab Page.
http://code.google.com/p/chromium/issues/detail?id=98871
Work-around:
1. Only use the bookmarklet on open pages. Use apple+click to open in a new tab.
2. Replace New Tab with about:blank
https://chrome.google.com/webstore/detail/pfdloiaebhgmjpaclbbodcmlmppkakjh
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment