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 g = 0; g < infoboxSpans.length; g++) { if(!originalValues[g]) { originalValues[g] = {}; var stat = infoboxSpans[g].innerHTML; if (stat.includes('x')) { originalValues[g].value = parseInt(parseFloat(stat.split('x')[1].replace(/,/g, ''))); originalValues[g].sep = 'x'; }               else if (stat.includes('+')) { originalValues[g].value = parseInt(parseFloat(stat.split('+')[1].replace(/,/g, ''))); originalValues[g].sep = '+'; }           }            if(!isNaN(originalValues[g].value) && !isNaN(enchant.value) && !isNaN(level.value)) { if(calculate(level.value, enchant.value, originalValues[i].value) == originalValues[g].value) { var headers = document.getElementsByClassName('pi-header') for (var x = 0; x < headers.length; x++) { if (headers[x].innerHTML == "Calculated Stats") { headers[x].innerHTML = "Base Stats" } else if (headers[x].innerHTML == "Calculated Shiny Stats") { headers[x].innerHTML = "Shiny Base Stats" }                   }                }                 else { var headers = document.getElementsByClassName('pi-header'); for (var z = z; z < headers.length; z++) { if (headers[z].innerHTML == "Base Stats") { headers[z].innerHTML = "Calculated Stats" } else if (headers[z].innerHTML == "Shiny Base Stats") { headers[z].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 a = 0; a < calculators.length; a++) { addStatsCalculator(calculators[a]); } }