MediaWiki:QutaManaCalculator.js

// Owner: Rus setTimeout(=> {   let template = Utils.get('QutaManaCalculator');    if(template == undefined) return;	    Utils.addMixin("shared-styles", { "min-height": "50px", width: "50%", fontSize: "15px", })   Utils.adMixin("red-text-underline", { color: "red", textDecoration: "underline", })   let input = Utils.create("textarea", { include: "shared-styles", resize: "none", placeholder: "Input goes here...", })   let output = Utils.create("div", { include: "shared-styles", textContent: "Output", 'margin-top': '5px', border: "1px solid black", display: 'flex', 'align-items': 'center', 'justify-content': 'center', })

input.oninput = function{ output.textContent = Elemental.simplify(input.value, {joinedResult: true, resultOnly: true }); }

input.oninput = function{ let balanced = Elemental.balance(input.value, {quantifyResult: true}); if(typeof balanced === 'string') return output.textContent = balanced; else { let mana = 0;

let totalReactantProtons = 0; let totalReactantElectrons = 0; let totalReactantNeutrons = 0;

let totalProductProtons = 0; let totalProductElectrons = 0; let totalProductNeutrons = 0;

let productElements = Object.keys(balanced.products); let reactantElements = Object.keys(balanced.reactants);

for(i = 0; i < productElements.length; i++){ totalProductProtons += Elemental.protons(productElements[i]) * balanced.products[productElements[i]]; totalProductElectrons += Elemental.electrons(productElements[i]) * balanced.products[productElements[i]]; totalProductNeutrons += Elemental.neutrons(productElements[i]) * balanced.products[productElements[i]]; }

for(i = 0; i < reactantElements.length; i++){ totalReactantProtons += Elemental.protons(reactantElements[i]) * balanced.reactants[reactantElements[i]]; totalReactantElectrons += Elemental.electrons(reactantElements[i]) * balanced.reactants[reactantElements[i]]; totalReactantNeutrons += Elemental.neutrons(reactantElements[i]) * balanced.reactants[reactantElements[i]]; }

totalProductProtons *= 100 totalReactantProtons *= 100

totalProductElectrons *= 10 totalReactantElectrons *= 10

totalProductNeutrons *= 50 totalReactantNeutrons *= 50

let totalProductPrecursor = totalProductProtons + totalProductElectrons + totalProductNeutrons; let totalReactantPrecursor = totalReactantProtons + totalReactantElectrons + totalReactantNeutrons;

mana = totalReactantPrecursor - totalProductPrecursor; if(mana > 0) mana = mana / 4 mana = Math.round(Math.abs(mana)) output.textContent = `Mana Used: ${mana}` }   }

template.appendChild(Utils.bundle([input, output])) }, 500)