Mr_FJ / ExplainXKCD button

// ==UserScript==
// @namespace    https://openuserjs.org/users/Mr_FJ
// @name         ExplainXKCD button
// @description  Adds an explain button to all XKCD comics.
// @copyright    2019, Mr_FJ (https://openuserjs.org/users/Mr_FJ)
// @grant        none
// @license      MIT
// @version      1.0
// @updateURL    https://openuserjs.org/meta/Mr_FJ/ExplainXKCD_button.meta.js
// @downloadURL  https://openuserjs.org/install/Mr_FJ/ExplainXKCD_button.user.js
// @match        https://*.xkcd.com/*
// ==/UserScript==

// ==OpenUserJS==
// @author Mr_FJ
// ==/OpenUserJS==

(function() {
    var nav = document.getElementsByClassName("comicNav");

    Array.from(nav).forEach(item => {
        var comicNumber = window.location.href.toString().split("com");
        var explainButton = document.createElement('li');
        var explainA = document.createElement('a')

        explainA.style.background = '#979797';
        if(comicNumber.length == 2)
        {
            explainA.href = '//explainxkcd.com' + comicNumber[1];
        }
        else
        {
            explainA.href = '//explainxkcd.com';
        }
        explainA.innerHTML = "Explain";
        explainButton.append(explainA);
        item.append(explainButton);
    });
})();