DarkYuan / ACDB Skill Collapser

// ==UserScript==
// @name         ACDB Skill Collapser
// @description  Please download the latest version at https://openuserjs.org/scripts/DarkYuan/ACDB_Tweaks
// @version      1.0.99
// @updateURL    https://openuserjs.org/meta/DarkYuan/ACDB_Skill_Collapser.meta.js
// @match        http://www.alchemistcodedb.com/*
// @namespace    http://tampermonkey.net/
// @grant        none
// @author       DarkYuan
// @copyright    2017, DarkYuan (http://darkyuan.tk/)
// @license      Zlib
// ==/UserScript==

// ==OpenUserJS==
// @author DarkYuan
// ==/OpenUserJS==

(function() {
    'use strict';

    // UPDATE NOTICE - Remove these 5 lines if not interested
    if (window.confirm("ACDB Skill Collapser has changed names to ACDB Tweaks and is now hosted under that name on OpenUserJS. " +
    "This script will no longer receive updates. You can download the new version simply by clicking OK below. " +
    "Or feel free to remove this notice from the source code if you're not interested.")) {
        window.location.href="https://openuserjs.org/scripts/DarkYuan/ACDB_Tweaks/"; }

    var curElement, headerType, hiddenTable, tablesToHide, buttonLocation;
    var hiddenTableList = [];
    var plusButton = "<a title=\'Expand/Collapse Table\' href=\'javascript:void(0);\' style=\'padding-right: 6px;\' onclick=\'" +
        "if (this.parentNode.className == \"card-header\") { tablesToHide = this.parentNode.parentNode.getElementsByTagName(\"table\"); } " +
        "else { tablesToHide = this.parentNode.parentNode.parentNode.getElementsByTagName(\"table\"); } " +
        "for (var t = 0; t < tablesToHide.length; t++) { " +
        "if (tablesToHide[t].style.display==\"none\") { tablesToHide[t].style.display=\"\"; } " +
        "else { tablesToHide[t].style.display=\"none\"; } }\'>[+/-]</a>";

    // Itterate through all caption elements
    var captionsList = document.getElementsByTagName("caption");
    for(var i = 0; i < captionsList.length; i++)
    {
        // If it matches
        curElement = captionsList[i];
        if (curElement.innerHTML.match(/(Skill Data)/)||
            curElement.innerHTML.match(/(Condition Data)/)||
            curElement.innerHTML.match(/(Buff Data)/)||
            curElement.innerHTML.match(/(Weapon Scaling Formula)/))
        {
            // Skip this table if in the Stats header
            if (curElement.parentNode.parentNode.parentNode.children[0] &&
                curElement.parentNode.parentNode.parentNode.children[0].innerHTML == "Stats") {
                continue;
            }

            // Store this table in a list for later
            hiddenTableList.push(curElement.parentNode);
        }
    }

    // Itterate through all matching tables
    for(var t = 0; t < hiddenTableList.length; t++)
    {
        // Make that table hidden
        hiddenTable = hiddenTableList[t];
        hiddenTable.style.display = "none";

        // Determine if it's a Leader Skill (card-body) or Ability
        if (hiddenTable.parentNode.className == "card-body") {
            buttonLocation = hiddenTable.parentNode.parentNode.children[0];
        } else {
            buttonLocation = hiddenTable.parentNode.children[0].children[0];
        }

        // Prepend a link with text of [+/-] if not already there
        if (!buttonLocation.children[0]) {
            buttonLocation.insertAdjacentHTML('afterbegin', plusButton);
        }
    }
})();