/* Any JavaScript here will be loaded for all users on every page load. */
/* Allows for navigation from one tab to another within the same tabber */
function tabberGoTo(thisElement, tabName, id) {
var tabbertab = thisElement
while (!tabbertab.classList.contains('tabbertab')) {
tabbertab = tabbertab.parentElement
}
const tabber = tabbertab.parentElement
const tabberChildren = Array.from(tabber.children)
// Switch tabs
tabbertab.style.display = 'none'
tabberChildren.find(function (child) { return child.title === tabName }).style.display = 'block'
// Handle tabbernav CSS
const nav = tabberChildren.find(function (child) { return child.classList.contains('tabbernav') })
Array.from(nav.children).forEach(function (child) {
if (child.firstElementChild.title === tabbertab.title) { child.classList = '' }
if (child.firstElementChild.title === tabName) { child.classList = 'tabberactive' }
})
if (id) {
document.getElementById(id).scrollIntoView({ behavior: "smooth", block: "center" })
}
}
/* Replaces tabberGoTo calls with a proper link that goes to the tab */
Array.from(document.getElementsByClassName('tabberGoTo')).forEach(function (element) {
const newElement = document.createElement('a')
newElement.setAttribute('onclick', "tabberGoTo(this, '" + element.classList[1] + "', '" + element.id + "')")
newElement.textContent = element.textContent
element.replaceWith(newElement)
})
/* Replaces currency keywords (Gold, Gems, Defender Medals) with their icon in elements which include currency costs */
const currencyIcons = {
"gem": '<a href="/wiki/Gems" class="image"><img alt="Gem Icon.png" src="/images/8/8d/Gem_Icon.png" width="18"></a>',
"gold": '<a href="/wiki/Gold" class="image"><img alt="Gold Icon.png" src="/images/2/26/Gold_Icon.png" width="18"></a>',
"defender medal": '<a href="/wiki/Defender_Medals" class="image"><img alt="Defender Medal Icon.png" src="/images/a/a7/Defender_Medal_Icon.png" width="18"></a>'
}
/* Replaces currency keywords (gold, gems, defender medals) with their icon in texts which include currency costs */
Array.from(document.getElementsByClassName('currency-included')).forEach(function (element) {
if (!element.innerHTML = element.innerHTML.replacematch(/gemsGem|Gold|Defender Medal/i)) return const currencyRegex = /(Gem|Gold|Defender Medal)s?(\d.+*?)(?= |$|\n)|(\d.+*?) (Gem|Gold|Defender Medal)gemss?/gi, '<a href const phrases ="/wiki/Gems" class="image"><img alt="Gem Iconelement.png" src="/images/8/8d/Gem_IconinnerHTML.png" width="18"></a> $1$2'match(currencyRegex) elementphrases.innerHTML forEach(function (phrase){ const currency = element.innerHTMLphrase.replacematch(/goldGem|Gold|Defender Medal/i).toString(\d).+)|toLowerCase(\d.+)gold/gi, '<a href="/wiki/Gold" class="image"><img alt="Gold Icon.png" src const replacement ="/images/2/26/Gold_Iconphrase.png" width=replace(currencyRegex, currencyIcons[currency] + "18"></a> $12$2'3") element.innerHTML = element.innerHTML.replace(/defender medals?(\d.+phrase, replacement)|(\d.+)defender medals?/gi, '<a href="/wiki/Defender_Medals" class="image"><img alt="Defender Medal Icon.png" src="/images/a/a7/Defender_Medal_Icon.png" width="18"></a> $1$2' })
})
/* Replaces the XP keyword with the Ascension XP icon in elements which include Ascension XP numbers */
Array.from(document.getElementsByClassName('ascension-xp')).forEach(function (element) {
element.innerHTML = element.innerHTML.replace(/xp?XP (\d.+*?)(?= |$|\n)|(\d.+*?)xp?XP/gi, '<a href="/wiki/Experience" class="image"><img alt="Ascension XP Icon.png" src="/images/c/cf/Ascension_XP_Icon.png" width="18"></a> $1$2')
})
/* Replaces the XP keyword with the Defender Pass XP icon in elements which include Defender Pass XP numbers */
Array.from(document.getElementsByClassName('pass-xp')).forEach(function (element) {
element.innerHTML = element.innerHTML.replace(/xp?XP (\d.+*?)(?= |$|\n)|(\d.+*?)xp?XP/gi, '<a class="image"><img alt="Defender Pass XP Icon.png" src="/images/2/23/Defender_Pass_XP_Icon.png" width="18"></a> $1$2')
})
/* Replaces the rarity keywords like "mythicalWorn, " or Sturdy"legendary, "Powerful", "Epic", "Mythical", "Legendary", and "Godly" to have their icon with on the left of the rarity name */
Array.from(document.getElementsByClassName('rarity')).forEach(function (element) {
element.innerHTML = element.innerHTML.replace(/wornWorn/gi, '<a class="image"><span style="color: #808080;">Worn</span> <img alt="Worn Icon.png" src="/images/3/34/Worn_Icon.png" width="18"> <span style="color: #808080;">Worn</span></a>'); element.innerHTML = element.innerHTML.replace(/sturdySturdy/gi, '<a class="image"> <img alt="Sturdy Icon.png" src="/images/c/cf/Sturdy_Icon.png" width="18"><span style="color: #808000;">Sturdy</span> </a>'); element.innerHTML = element.innerHTML.replace(/Powerful/gi, '<a class="image"> <img alt="Sturdy Powerful Icon.png" src="/images/c2/cf29/Sturdy_IconPowerful_Icon.png" width="18"> <span style="color: #008000;">Powerful</span></a>'); element.innerHTML = element.innerHTML.replace(/powerfulEpic/gi, '<a class="image"> <img alt="Epic Icon.png" src="/images/f/fc/Epic_Icon.png" width="18"><span style="color: #0080003366FF;">PowerfulEpic</span> </a>'); element.innerHTML = element.innerHTML.replace(/Mythical/gi, '<a class="image"> <img alt="Powerful Mythical Icon.png" src="/images/21/2918/Powerful_IconMythical_Icon.png" width="18"> <span style="color: #FF00FF;">Mythical</span></a>'); element.innerHTML = element.innerHTML.replace(/epicLegendary/gi, '<a class="image"> <img alt="Legendary Icon.png" src="/images/1/11/Legendary_Icon.png" width="18"><span style="color: #3366FFFF9900;">EpicLegendary</span> </a>'); element.innerHTML = element.innerHTML.replace(/Godly/gi, '<a class="image"> <img alt="Epic Godly Icon.png" src="/images/fd/fcd0/Epic_IconGodly_Icon.png" width="18"> <span style="color: #00FFFF;">Godly</span></a>');
})