XKCD Explain Button

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

Installer dette script?
Skaberens foreslåede script

Du vil måske også kunne lide XKCD - Display Title Below Comic

Installer dette script
// ==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>`)
})