MediaWiki:QutaManaCalculator.js

// Owner: Rus setTimeout(=> {   let template = Utils.get('QutaManaCalculator');    if(template == undefined) return;		let input = Utils.create("textarea")	    let output = Utils.create("div")	    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)