Changes

MediaWiki:Common.js

1,197 bytes added, 06:55, 16 November 2023
Amending regex again
/* Any JavaScript here will be loaded for all users on every page load. */
/* Replaces currency keywords (goldGold, gemsGems, defender medalsDefender Medals) with their icon in texts 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>'} 
Array.from(document.getElementsByClassName('currency-included')).forEach(function (element) {
element.innerHTML = if (!element.innerHTML.replacematch(/gemsGem|Gold|Defender Medal/i)) return const currencyRegex = /(Gem|Gold|Defender Medal)s?(\sd.*?)([?= |$|\d,]+n)|([\d,]+.*?) (Gem|Gold|Defender Medal)\s*?gems?/gi, '<a href="/wiki/File:Gem_Icon.png" class="image"><img alt="Gem Icon.png" src="/images/8/8d/Gem_Icon.png" width="18"></a> $1$2') element.innerHTML const phrases = element.innerHTML.replacematch(/gold\s*?currencyRegex) phrases.forEach([\d,]+)|function ([\d,]+phrase)\s*?gold/gi, '<a href{ const currency ="phrase.match(/wikiGem|Gold|Defender Medal/File:Gold_Iconi).png" class="image"><img alt="Gold IcontoString().png" srctoLowerCase() 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?\s*?([\dphrase,]+replacement)|([\d,]+)\s*?defender medals?/gi, '<a href="/wiki/File:Defender_Medal_Icon.png" class="image"><img alt="Defender Medal Icon.png" src="/images/a/a7/Defender_Medal_Icon.png" width="18"></a> $1$2' })
})
window/* Replaces the XP keyword with the Ascension XP icon in elements which include Ascension XP numbers */Array.from(document.getElementsByClassName('ascension-xp')).tooltips_config = forEach(function (element) { waitForImages: true, noCSS: trueelement.innerHTML = element.innerHTML.replace(/XP (\d.*?)(?= |$|\n)|(\d.*?) 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')};)
window/* Replaces the XP keyword with the Defender Pass XP icon in elements which include Defender Pass XP numbers */Array.from(document.tooltips_list = [ { classname: getElementsByClassName('unitpass-tooltipxp')).forEach(function (element) { element.innerHTML = element.innerHTML.replace(/XP (\d.*?)(?= |$|\n)|(\d.*?) XP/gi, parse: '{'+'{<#unit#>|ranka class=<#rank#"image">|size=<#size#>|upgradeimg alt=<#upgrade#>|upgrades"Defender Pass XP Icon.png" src=<#upgrades#>|upgraded"/images/2/23/Defender_Pass_XP_Icon.png" width=<#upgraded#"18">|race=<#race#/a>|tt=<#tt#>|show=no$1$2')}}',)  /* Replaces the rarity keywords like "Worn, "Sturdy", "Powerful", "Epic", "Mythical", "Legendary", and "Godly" to have their icon on the left of the name */onShow: functionArray.from() { if ((this)document.getElementsByClassName('template-unitrarity')[0]).forEach(function (element) {Unit element.innerHTML = (this)element.innerHTML.getElementsByClassNamereplace(/Worn/gi, 'template-unit')[0]; console<a class="image"> <img alt="Worn Icon.png" src="/images/3/34/Worn_Icon.info(png" width="18"Onshow var > <span style=",Unit)color: #808080; processunit (Unit">Worn</span> </a>');} }, }element.innerHTML = element.innerHTML.replace(/Sturdy/gi, { classname: 'spell-tooltip', parse: '{'+'{<#spell#a class="image">|magnitude<img alt="Sturdy Icon.png" src="/images/c/cf/Sturdy_Icon.png" width="18"> <span style="color: #magnitude#808000;">Sturdy</span>|tt=<#tt#/a>}}',); }element.innerHTML = element.innerHTML.replace(/Powerful/gi, { classname: 'ability-tooltip', parse: '{'+'{<#ability#a class="image"> <img alt="Powerful Icon.png" src="/images/2/29/Powerful_Icon.png" width="18">|<span style="color: #magnitude#008000;">|duration=Powerful<#duration#/span>|tt=<#tt#/a>|show=no}}',); }element.innerHTML = element.innerHTML.replace(/Epic/gi, { classname: 'structure-tooltip', parse<a class="image"> <img alt="Epic Icon.png" src="/images/f/fc/Epic_Icon.png" width="18"> <span style="color: '{'+'{#3366FF;">Epic<#structure#/span>}}', }, { classname: 'building-tooltip', parse: '{'+'{<#building#/a>}}',); }, { classname: 'damageability-tooltip'element.innerHTML = element.innerHTML.replace(/Mythical/gi, parse: '{'+'{<#ability#a class="image">|physical<img alt=<#physical#>|spirit"Mythical Icon.png" src=<#spirit#>|blight"/images/1/18/Mythical_Icon.png" width=<#blight#"18">|fire=<#fire#>|frostspan style=<#frost"color: #FF00FF;">|shock=Mythical<#shock#/span>|tt=<#tt#/a>|show=no}}', onShow: function(handle) { a = handle; writeloc element.innerHTML = (this)element.innerHTML.getElementsByClassNamereplace(/Legendary/gi, 'writedamage')[0]; damagesource <a class="image"> <img alt= a"Legendary Icon.parentElement; unitloc png" src= damagesource"/images/1/11/Legendary_Icon.parentElement.parentElementpng" width="18"> <span style="color: #FF9900; damageCalc (writeloc, damagesource, unitloc">Legendary</span> </a>'); }, }, { classname: 'protection-tooltip'element.innerHTML = element.innerHTML.replace(/Godly/gi, parse: '{'+'{Prottable|<#magnitude#a class="image"> <img alt="Godly Icon.png" src="/images/d/d0/Godly_Icon.png" width="18">|<span style="color: #element#00FFFF;">}}', }, { classname: 'weakness-tooltip', parse: '{'+'{Weaktable|Godly<#magnitude#/span>|<#element#/a>}}',); }];)
WikiDefender, bureaucrat, administrator
617
edits