MediaWiki:QutaManaCalculator.js

// Owner: Rus setTimeout( => {	let containerName = "QutaManaCalculator";	try {	   let container = Utils.get(containerName);	    if(container == undefined) return;

Utils.addMixin("shared", {	       "min-height": "50px",	        width: "50%",	        fontSize: "18px",	    }) let input = Utils.create("textarea", {	       include: "shared",	        resize: "none",	        placeholder: "Input goes here... (ex. C6H12O6 + O2 -> CO2 + H2O)",	    }) let output = Utils.create("div", {	       include: "shared",	        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 *= 10 totalReactantProtons *= 10 totalProductElectrons *= 3 totalReactantElectrons *= 3 totalProductNeutrons *= 2 totalReactantNeutrons *= 2 mana = (totalProductProtons - totalReactantProtons) + (totalProductElectrons - totalReactantElectrons) + (totalProductNeutrons - totalReactantNeutrons); if(mana < 0) mana = Math.abs(mana) / 10; mana = Math.round(mana) output.textContent = `Mana used: ${mana.toLocaleString}`; }	   }	    container.appendChild(Utils.bundle([input, output])) } catch (error) { document.getElementById(containerName).classList.add("js-error") } }, 500)