User:TotallyNotJullian/global.js

importArticles({   type: 'script',    articles: [        'u:dev:MediaWiki:MassEdit/code.js',    ] }); window.massEditConfig = { editInterval: 1500 }; importArticles({   type: 'script',    articles: [        'u:dev:MediaWiki:RailWAM/code.js'    ] });

const originalValues = {}; String.prototype.commafy = function { return this.replace(/(^|[^\w.])(\d{4,})/g, function($0, $1, $2) {       return $1 + $2.replace(/\d(?=(?:\d\d\d)+(?!\d))/g, "$&,");    }); }; Number.prototype.commafy = function { return String(this).commafy; }; function addStatsCalculator(element) { var level = document.createElement("input"); var levelLabel = document.createElement("label"); levelLabel.innerHTML = "Level "; var enchant = document.createElement("input"); var enchantLabel = document.createElement("label"); enchantLabel.innerHTML = "Enchant "; var submit = document.createElement("button"); submit.innerHTML = "Calculate"; submit.onclick = function { function calculate(level, enchant, stat) { var l = 1; var e = 0; if (level !== undefined) { l = level; }           if (enchant !== undefined) { e = enchant; }           var res = parseInt(stat + ((stat * 2) - stat) * (l - 1) / (25 - 1)); return parseInt(res + ((res * 1.5) - res) * e / 40); }       var infobox = document.getElementsByClassName("portable-infobox")[0]; var infoboxSpans = infobox.getElementsByTagName("span"); for (var i = 0; i < infoboxSpans.length; i++) { if(!originalValues[i]) { originalValues[i] = {}; var stat = infoboxSpans[i].innerHTML; if (stat.includes('x')) { originalValues[i].value = parseInt(parseFloat(stat.split('x')[1].replace(/,/g, ''))); originalValues[i].sep = 'x'; }               else if (stat.includes('+')) { originalValues[i].value = parseInt(parseFloat(stat.split('+')[1].replace(/,/g, ''))); originalValues[i].sep = '+'; }           }            if(!isNaN(originalValues[i].value) && !isNaN(enchant.value) && !isNaN(level.value)) { if(calculate(level.value, enchant.value, originalValues[i].value) == originalValues[i].value) { if (document.getElementsByClassName('pi-header')[5]) { document.getElementsByClassName('pi-header')[0].innerHTML = "Base Stats"; document.getElementsByClassName('pi-header')[3].innerHTML = "Base Shiny Stats"; } else if(document.getElementsByClassName('pi-header')[3]) { document.getElementsByClassName('pi-header')[0].innerHTML = "Base Stats"; document.getElementsByClassName('pi-header')[2].innerHTML = "Base Shiny Stats"; } else if (document.getElementsByClassName('pi-header')[2]) { document.getElementsByClassName('pi-header')[0].innerHTML = "Base Stats"; document.getElementsByClassName('pi-header')[2].innerHTML = "Base Shiny Stats"; } else if (document.getElementsByClassName('pi-header')[1]) { document.getElementsByClassName('pi-header')[0].innerHTML = "Base Stats"; document.getElementsByClassName('pi-header')[1].innerHTML = "Base Shiny Stats"; }               }                 else { if (document.getElementsByClassName('pi-header')[5]) { document.getElementsByClassName('pi-header')[0].innerHTML = "Calculated Stats"; document.getElementsByClassName('pi-header')[3].innerHTML = "Calculated Shiny Stats"; } else if(document.getElementsByClassName('pi-header')[3]) { document.getElementsByClassName('pi-header')[0].innerHTML = "Calculated Stats"; document.getElementsByClassName('pi-header')[2].innerHTML = "Calculated Shiny Stats"; } else if (document.getElementsByClassName('pi-header')[2]) { document.getElementsByClassName('pi-header')[0].innerHTML = "Calculated Stats"; document.getElementsByClassName('pi-header')[2].innerHTML = "Calculated Shiny Stats"; } else if (document.getElementsByClassName('pi-header')[1]) { document.getElementsByClassName('pi-header')[0].innerHTML = "Calculated Stats"; document.getElementsByClassName('pi-header')[1].innerHTML = "Calculated Shiny Stats"; }               }                infoboxSpans[i].innerHTML = originalValues[i].sep + calculate(level.value, enchant.value, originalValues[i].value).commafy; }       }    };      element.append(        levelLabel, level, document.createElement("br"),        enchantLabel, enchant, document.createElement("br"),        submit      ); } if (document.getElementsByClassName("calculator")[0] !== undefined) { var calculators = document.getElementsByClassName('calculator'); for (var i = 0; i < calculators.length; i++) { addStatsCalculator(calculators[i]); } }