XKCD Explain Button

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

安装此脚本?
作者推荐脚本

您可能也喜欢XKCD - Display Title Below Comic

安装此脚本
  1. // ==UserScript==
  2. // @name XKCD Explain Button
  3. // @namespace Violentmonkey Scripts
  4. // @match *://*.xkcd.com/*
  5. // @grant none
  6. // @version 1.0.1
  7. // @author Jonah Lawrence - youtube.com/DevProTips
  8. // @description Add a button to XKCD comics next to the "Random" button which links to the explainxkcd for the current comic
  9. // ==/UserScript==
  10.  
  11. // locate all of the "Random" buttons on the page
  12. Array.from(document.querySelectorAll(".comicNav a[href*='random']")).forEach(x => {
  13. // get the meta tag containing the fully qualified comic url and replace xkcd with explainxkcd
  14. let explainUrl = document.querySelector(".comicNav ~ a[href^='https://xkcd.com/']").href.replace("xkcd","explainxkcd")
  15. // insert a new item before the random button linking to the explainxkcd url
  16. x.parentElement.insertAdjacentHTML("beforeBegin",`<li><a href='${explainUrl}'>Explain</a></li>`)
  17. })