XKCD Explained

Adds a button to XKCD Explained in the navigation toolbar

目前為 2015-06-12 提交的版本,檢視 最新版本

  1. // ==UserScript==
  2. // @name XKCD Explained
  3. // @namespace http://www.explainxkcd.com/
  4. // @description Adds a button to XKCD Explained in the navigation toolbar
  5. // @include http://xkcd.com/*
  6. // @include https://xkcd.com/*
  7. // @grant none
  8. // @version 1
  9. // ==/UserScript==
  10. var comicNumber = parseInt(window.location.pathname.replace(/\//g,'')),
  11. comicNavbar = comicNavbar = document.getElementsByClassName('comicNav')[0],
  12. previousComicURL, comicUrl, explainNavbar;
  13. if(!comicNumber) {
  14. previousComicURL = comicNavbar.children[1].firstChild.href;
  15. comicNumber = parseInt(previousComicURL.match('[0-9]+')) + 1;
  16. }
  17. comicUrl = 'http://www.explainxkcd.com/wiki/index.php?title=' + comicNumber;
  18. explainNavbar = document.createElement('ul');
  19.  
  20. explainNavbar.className = 'comicNav';
  21.  
  22. explainNavbar.innerHTML = '<li><a target="_blank" href="' + comicUrl + '">Explanation</a></li>';
  23. comicNavbar.parentNode.insertBefore(explainNavbar, comicNavbar);