XKCD Explain Button

Add a button to XKCD comics next to the "Random" button which links to the explainxkcd for the current comic

Install this script?
Author's suggested script

You may also like XKCD - Display Title Below Comic.

Install this script

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Userscripts to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name        XKCD Explain Button
// @namespace   Violentmonkey Scripts
// @match       *://*.xkcd.com/*
// @grant       none
// @version     1.0.1
// @author      Jonah Lawrence - youtube.com/DevProTips
// @description Add a button to XKCD comics next to the "Random" button which links to the explainxkcd for the current comic
// ==/UserScript==

// locate all of the "Random" buttons on the page
Array.from(document.querySelectorAll(".comicNav a[href*='random']")).forEach(x => {
  // get the meta tag containing the fully qualified comic url and replace xkcd with explainxkcd
  let explainUrl = document.querySelector(".comicNav ~ a[href^='https://xkcd.com/']").href.replace("xkcd","explainxkcd")
  // insert a new item before the random button linking to the explainxkcd url
  x.parentElement.insertAdjacentHTML("beforeBegin",`<li><a href='${explainUrl}'>Explain</a></li>`)
})