MediaWiki:Common.js: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
No edit summary |
||
Line 13: | Line 13: | ||
const inputGoldPerfect = document.createElement("input"); | const inputGoldPerfect = document.createElement("input"); | ||
inputGoldPerfect.type = "number"; | inputGoldPerfect.type = "number"; | ||
inputGoldPerfect.size = 4; | |||
root.appendChild(inputGoldPerfect); | root.appendChild(inputGoldPerfect); | ||
const inputAnyPerfect = document.createElement("input"); | const inputAnyPerfect = document.createElement("input"); | ||
inputAnyPerfect.type = "number"; | inputAnyPerfect.type = "number"; | ||
inputAnyPerfect.size = 4; | |||
root.appendChild(inputAnyPerfect); | root.appendChild(inputAnyPerfect); | ||
const inputGreat = document.createElement("input"); | const inputGreat = document.createElement("input"); | ||
inputGreat.type = "number"; | inputGreat.type = "number"; | ||
inputGreat.size = 4; | |||
root.appendChild(inputGreat); | root.appendChild(inputGreat); | ||
const inputGood = document.createElement("input"); | const inputGood = document.createElement("input"); | ||
inputGood.type = "number"; | inputGood.type = "number"; | ||
inputGood.size = 4; | |||
root.appendChild(inputGood); | root.appendChild(inputGood); | ||
const inputMiss = document.createElement("input"); | const inputMiss = document.createElement("input"); | ||
inputMiss.type = "number"; | inputMiss.type = "number"; | ||
inputMiss.size = 4; | |||
root.appendChild(inputMiss); | root.appendChild(inputMiss); | ||
Line 35: | Line 40: | ||
root.appendChild(calculateBtn); | root.appendChild(calculateBtn); | ||
const output = document.createElement(" | const output = document.createElement("p"); | ||
root.appendChild(output); | root.appendChild(output); | ||
Revision as of 19:34, 17 August 2024
/* Any JavaScript here will be loaded for all users on every page load. */ function findAndExecute(selector, callback) { const elements = document.querySelectorAll(selector); elements.forEach((element) => { callback(element); }); } findAndExecute(".rgwiki-gadvia-score-calculator", (root) => { root.textContent = ""; const inputGoldPerfect = document.createElement("input"); inputGoldPerfect.type = "number"; inputGoldPerfect.size = 4; root.appendChild(inputGoldPerfect); const inputAnyPerfect = document.createElement("input"); inputAnyPerfect.type = "number"; inputAnyPerfect.size = 4; root.appendChild(inputAnyPerfect); const inputGreat = document.createElement("input"); inputGreat.type = "number"; inputGreat.size = 4; root.appendChild(inputGreat); const inputGood = document.createElement("input"); inputGood.type = "number"; inputGood.size = 4; root.appendChild(inputGood); const inputMiss = document.createElement("input"); inputMiss.type = "number"; inputMiss.size = 4; root.appendChild(inputMiss); const calculateBtn = document.createElement("button"); calculateBtn.textContent = "Calculate"; root.appendChild(calculateBtn); const output = document.createElement("p"); root.appendChild(output); calculateBtn.addEventListener("click", () => { const goldPerfect = Number(inputGoldPerfect.value); const anyPerfect = Number(inputAnyPerfect.value); const great = Number(inputGreat.value); const good = Number(inputGood.value); const miss = Number(inputMiss.value); const hitNotes = anyPerfect + great + good; const totalNotes = anyPerfect + great + good + miss; const nonGoldPerfect = anyPerfect - goldPerfect; const score = Math.floor((anyPerfect + (great * 0.8) + (good * 0.5)) / totalNotes * 1000000) + (goldPerfect * 0.0001); output.textContent = `Score: ${score} - Hit notes: ${hitNotes}/${totalNotes} - Non-gold perfects: ${nonGoldPerfect}`; }); });