XKCD Explain Button

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

Version vom 26.10.2020. Aktuellste Version

// ==UserScript==
// @name        XKCD Explain Button
// @namespace   Violentmonkey Scripts
// @match       *://*.xkcd.com/*
// @grant       none
// @version     1.0
// @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("meta[property='og:url']").content.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>`)
})
长期地址
遇到问题?请前往 GitHub 提 Issues,或加Q群1031348184

赞助商

Fishcpy

广告

Rainyun

一年攒够 12 元

云驰互联

云驰互联