Favicon.png
xkcdFavicon.png

Browser helpers

Explain xkcd: It's 'cause you're dumb.
Revision as of 00:55, 4 May 2022 by 162.158.162.215 (talk) (Undo revision 233655 by X. K. C. D. (talk))
Jump to: navigation, search


Over the years, a number of people have developed various "helpers" to conveniently access a comic's explanation here at this wiki when browsing at xkcd. These typically come in three main forms: browser extensions, userscripts, and bookmarklets.

Browser extensions

These browser extensions/add-ons usually inject elements/code into the xkcd.com comic page's DOM – often inserting a button or link directly into the xkcd.com comic page itself, to take you to that comic's explanation page. None of these have been tested here.

Chrome

From the Chrome Web Store:

Extension Author Released Users[ec 1] Description
explainxkcd ripper234 November 2012 54 Adds an address bar button that pops up the comic's explanation.
xkcd Explainer Simon Zou June 2014 3 Adds an "I don't get it..." button to the comic page.
Explain XKCD Link jkirrane January 2015 17 Adds an explanation link to the comic page.
Explain XKCD Daniel F March 2015 7 Adds a browser extension button that pops up a minimal explanation.
XKCD Enhancer amalbose December 2015 12 Adds a button to the comic page that pops up the comic's explanation; also displays the title text.
Explain xkcd Linker Martin Petkov February 2017 10 Adds an explanation link to the comic page.
Explain xkcd Martin Frodl October 2017 1 Adds a browser extension button that pops up a minimal explanation.
xkcd-companion Sean Yeh August 2018 7 Adds an explanation link to the comic page; also displays the title text.
XKCD Explainer contact.chilikkal October 2018 34 Adds a "Huh?" button to the comic page.
explain xkcd kylejlin.dev December 2018 26 Adds a browser extension button that navigates to the comic's explanation page. See also Chrome Extension for more information on this extension.
xkcd Enhancer Tom White February 2019 35 Adds an explanation link to the comic page; also adds keyboard shortcuts, displays the title text, etc.
xkcd explainer Avadonia314 April 2019 18 Adds an "Explanation" button to the comic page, which loads the content of the comic's explanation directly into the page.
embetter xkcd Matt Sugihara May 2020 2 Press 'E' to navigate to the explanation; also adds other keyboard shortcuts and displays the title text.
xkcd Explanifier TheUltimateGuide August 2020 2 Adds a browser extension button that pops up another button that navigates to the explanation.
  1. Number of users as of September 28, 2020.

Firefox

From Mozilla Firefox Browser Add-ons:

Extension Author Released Users[ef 1] Description
xkcd Companion Sean Yeh July 2018 16 Adds an explanation link to the comic page; also displays the title text.
XKCD Explainer Yechiel K October 2018 46 Adds a "Huh?" button to the comic page.
XKCD Enhancer AstroRP March 2019 1 Adds an explanation button to the comic page; also redirects to m.xkcd.com on mobile devices.
ExplainXKCD Button David Hickey March 2019 1 Replaces the store link (or other link) on the comic page with a link to the explanation.
Explain XKCD Newt July 2019 14 Adds an address bar button.
xkcd Explanifier TheUltimateGuide August 2020 1 Adds a browser extension button that pops up another button that navigates to the explanation.
  1. Number of users as of September 28, 2020.

Edge

From Microsoft Edge Add-ons:

Extension Author Released Description
xkcd Explanifier TheUltimateGuide August 2020 Adds a browser extension button that pops up another button that navigates to the explanation.

Userscripts

Userscripts provide basically the same functions as the browser extensions above, manipulating xkcd.com's DOM to insert buttons/links or otherwise alter the page. The difference is that you can view/edit the code of these userscripts; however, they require a userscript manager such as Greasemonkey or Tampermonkey to run. None of these userscripts have been tested here.

Userscript managers:

Userscripts:

Mostly from Greasy Fork and OpenUserJS, with a few from GitHub repositories or Gists:

Userscript Author Source Released Description
xkcd+ LouCypher Greasy Fork March 2014 Adds a "?" button to the comic page; also adds an "i" button for the official transcript, and social media sharing buttons.
xkcd Title and Explain Doodles Greasy Fork July 2014 Adds an "Explanation" button to the comic page; also displays the title text.
xkcd buttons Alt+Transcript+Explainxkcd SammaySarkar Greasy Fork December 2014 Adds an "Explain" button to the comic page; also adds buttons to display the title text and official transcript, and keyboard shortcuts.
XKCD enhancements JonnyRobbie Greasy Fork March 2015 Converts the comic name into an "ExplainXKCD" link when hovering your mouse pointer over it; also displays the title text by clicking the comic.
explain_xkcd.js magazov GitHub Gist April 2015 Adds an "Explain" button to the comic page.
XKCD tooltip Lorentz83 Greasy Fork April 2016 Adds an explanation link; also displays the title text.
xkcd: Add explainxkcd.com links to comics Daniel del Zorro Multicolor (Foxical Paradox) Greasy Fork August 2016 Adds an explanation link.
Explain XKCD Button obskyr OpenUserJS February 2017 Adds an explanation link.
xkcd title text Tilwa Qendov Greasy Fork January 2018 Adds an explanation link; also displays the title text, and adds links to signed prints in the xkcd store.
xkcd Tweaks MitalAshok Greasy Fork February 2018 Adds an "Explain!" link; also displays the title text, adds keyboard shortcuts, and various other modifications.
Explain XKCD Button BigTSDMB OpenUserJS April 2018 Adds an explanation link.
ExplainXKCD-Button Userscript David-Hickey GitHub January 2019 Replaces the store link (or other link) on the comic page with a link to the explanation.
ExplainXKCD button Mr_FJ OpenUserJS July 2019 Adds an explanation button.
explain_xkcd.user.js lastsecondsave GitHub Gist December 2019 Adds an explanation button.
XKCD Explain Button saamirt Greasy Fork March 2020 Adds an "Explanation" button to the comic page.

Bookmarklets

Instead of a browser add-on/extension, you can create a bookmarklet to take you from an xkcd.com comic page to the corresponding explainxkcd.com explanation page. A bookmarklet is a browser bookmark/favorite, except instead of containing a URL to a webpage, it contains custom JavaScript code to perform the desired operation. The easiest way to create a bookmarklet in your browser is to first create a normal bookmark/favorite for any webpage, then edit that new bookmark to paste in the JavaScript code as the new "location"/"URL"/"address" of the bookmark. General instructions for creating and editing bookmarks in various web browsers are as follows:

Select one of the JavaScript code snippets below to copy/paste as the bookmarklet's URL/location. To use it, browse to an xkcd.com comic webpage, then while on that page, invoke the bookmark/favorite.

These have been tested in Firefox 80, Chrome 85, Edge 85, Opera 71, and Safari 13.

Concise

These "concise" bookmarklets are shorter and easier to read one-liners, and should mostly work OK, but might produce errors if used on webpages other than xkcd comics.

Same tab:

javascript:location.hostname='explainxkcd.com'

New tab/window:

javascript:void open(location.href.replace('xkcd.com','explainxkcd.com'))

Verbose

These "verbose" bookmarklets are longer and harder to read (as they also validate that you are, in fact, on an xkcd.com comic page before attempting to load the corresponding explanation page), but they are technically more "correct". Note that each of these is a single line of code, despite any word-wrapping.

Same tab:

javascript:(function() { "use strict"; const isXkcdDotCom = (window.location.hostname === "xkcd.com"); const isComicPage = (new RegExp(/^\/$|^\/\d+\/$/).test(window.location.pathname)); if (isXkcdDotCom && isComicPage) { window.location.hostname = "explainxkcd.com"; } else { window.alert("The current page does not appear to be an xkcd comic page."); } }());

New tab/window:

javascript:(function() { "use strict"; const isXkcdDotCom = (window.location.hostname === "xkcd.com"); const isComicPage = (new RegExp(/^\/$|^\/\d+\/$/).test(window.location.pathname)); if (isXkcdDotCom && isComicPage) { const newLocation = new URL(window.location.href); newLocation.hostname = "explainxkcd.com"; window.open(newLocation.href, "_blank"); } else { window.alert("The current page does not appear to be an xkcd comic page."); } }());

Code explanation:

javascript:

// As a best practice, encapsulate everything within a self-invoking function,
// to not interfere with the global namespace of the current page.
(function() {
  "use strict";
  // Develop in "strict" mode, to be more picky.

  // Check if we're at exactly the root domain of xkcd.com,
  // no "www" (which redirects to the root domain anyway), and no subdomains.
  // Also no need to worry about the protocol,
  // as both xkcd.com and explainxkcd.com redirect from HTTP to HTTPS.
  const isXkcdDotCom = (window.location.hostname === "xkcd.com");

  // Check if we're on a comic page.
  // The path for a comic will be either the root of the site ("/") for the current comic,
  // or a numbered page ("/123/").
  const isComicPage = (new RegExp(/^\/$|^\/\d+\/$/).test(window.location.pathname));

  // The above regular expression is explained as follows:
  // / = begin regex.
  //     ^  = match the beginning of the string (i.e. require it to be the first thing in the path).
  //     \/ = match a forward-slash (must be escaped with a back-slash).
  //     $  = match the end of the string (i.e. require it to be the last thing in the path).
  //   | = match EITHER the regex above (i.e. the root path), OR the regex below (i.e. a comic number).
  //     ^  = match the beginning of the string (i.e. require it to be the first thing in the path).
  //     \/ = match a forward-slash (must be escaped with a back-slash).
  //     \d = match a decimal digit.
  //     +  = match ONE OR MORE of the preceding item (i.e. one or more decimal digits).
  //     \/ = match a forward-slash (must be escaped with a back-slash).
  //     $  = match the end of the string (i.e. require it to be the last thing in the path).
  // / = end regex.

  if (isXkcdDotCom && isComicPage) {
    // Yes, we're on a valid comic page at xkcd.com,
    // so navigate to the corresponding page at explainxkcd.com.

    // Get a copy of the current URL, ...
    const newLocation = new URL(window.location.href);

    // ...set its domain to explainxkcd.com...
    newLocation.hostname = "explainxkcd.com";

    // ...and open it in a new tab/window by specifying the target as "_blank".
    window.open(newLocation.href, "_blank");

    // For the xkcd.com site root (which is the most recent comic),
    // this will take us to the main page at explainxkcd.com,
    // which also has the explanation for the most recent comic.

    // For numbered comic pages, this will navigate to explainxkcd.com/<number>/,
    // which redirects to the correct page for that comic number.

  } else {
    // We're not on a comic page at xkcd.com,
    // so show an error message instead of navigating to explainxkcd.com.
    window.alert("The current page does not appear to be an xkcd comic page.");
  }
}());

Tap, tap, PERL!

Inspired by the following suggestions: