DarkYuan / ACDB Tweaks

// ==UserScript==
// @name         ACDB Tweaks
// @description  Quality of Life Tweaks for Alchemist Code Database (alchemistcodedb.com) Soul Shard Unit Links
// @version      1.1.2
// @updateURL    https://openuserjs.org/meta/DarkYuan/ACDB_Tweaks.meta.js
// @match        http://www.alchemistcodedb.com/*
// @namespace    https://openuserjs.org/
// @grant        none
// @author       DarkYuan
// @copyright    2017, DarkYuan (http://darkyuan.tk/)
// @license      Zlib
// ==/UserScript==

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

(function() {
    'use strict';
    var curElement;

    /////////////////////////
    // SOUL SHARD UNIT LINK
    if (true) { // Set to false to disable this feature

        // Detect if page contains a "Item Header" and a soul shard item type
        var targetURL = window.location.href;
        if (targetURL.indexOf("it-pi-") != -1) {

            // Get the unit's stylized name
            var soulShardHeaders = document.getElementsByClassName("h5 mb-1");
            var unitName = soulShardHeaders[0].parentNode.textContent;

            if (unitName.indexOf(" Soul Shard") != -1) { // For English Names
                unitName = unitName.substring(unitName.indexOf(0), unitName.indexOf(" Soul Shard")); }
            else { // For Japanese Names
                unitName = unitName.substring(unitName.indexOf(0), unitName.indexOf("の魂の欠片")); }

            // Modify the URL to its corresponding unit page
            targetURL = targetURL.replace(/(it-pi-)/g, "");
            targetURL = targetURL.replace(/(item)/g, "unit");
            var unitLink = "<a title=\'Unit Page\' href=\'" + targetURL + "\'>Go to " + unitName + "\'s Unit Page</a>";

            for(var h = 0; h < soulShardHeaders.length; h++)
            {
                // Put in a link at the bottom of the description
                curElement = soulShardHeaders[h].parentNode;
                curElement.insertAdjacentHTML('beforeend', unitLink);
            }
        }
    }
})();