MediaWiki:QutaManaCalculator.js

// Owner: Rus let containerName = "QutaManaCalculator" // your container name here setTimeout( => {	try {	   let container = Utils.get(templateName);	    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 *= 5 totalReactantProtons *= 5 totalProductElectrons *= 3 totalReactantElectrons *= 3 totalProductNeutrons *= 2 totalReactantNeutrons *= 2 let totalProductPrecursor = totalProductProtons + totalProductElectrons + totalProductNeutrons; let totalReactantPrecursor = totalReactantProtons + totalReactantElectrons + totalReactantNeutrons; mana = (totalProductProtons / totalReactantProtons) + (totalProductElectrons + totalReactantElectrons) + (totalProductNeutrons ** 2 + totalReactantNeutrons); // if everything is balanced, mana should be 1 let balancedProductElements = Object.keys(balanced.products); let balancedReactantElements = Object.keys(balanced.reactants); for(i = 0; i < balanced.balanced.length; i++){ if(Object.keys(balanced.products).includes(balanced.balanced[i]) && Object.keys(balanced.reactants).includes(balanced.balanced[i]) && !Object.keys(balanced.generated).includes(balanced.balanced[i])){ mana = 0; }	           }	            mana = Math.round(mana) output.textContent = `Mana used: ${mana.toLocaleString}`; }	   }	    container.appendChild(Utils.bundle([input, output])) } catch (error) { document.getElementById(containerName).classList.add("js-template-error") } }, 500)