MediaWiki:Common.js: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
No edit summary |
||
Line 22: | Line 22: | ||
const inputElement = document.createElement("input"); | const inputElement = document.createElement("input"); | ||
inputElement.type = "number"; | inputElement.type = "number"; | ||
inputElement.size = | inputElement.size = 8; | ||
fieldContainer.appendChild(inputElement); | fieldContainer.appendChild(inputElement); | ||
Line 30: | Line 30: | ||
const fields = document.createElement("div"); | const fields = document.createElement("div"); | ||
fields.style.display = "flex"; | fields.style.display = "flex"; | ||
fields.style.gap = "1em"; | |||
fields.style.alignItems = "end"; | |||
const inputGoldPerfect = createFormField(fields, "Gold Perfect"); | const inputGoldPerfect = createFormField(fields, "Gold Perfect"); |
Revision as of 19:48, 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 = ""; function createFormField(root, labelText) { const fieldContainer = document.createElement("div"); fieldContainer.style.display = "flex"; fieldContainer.style.flexDirection = "column"; const label = document.createElement("label"); label.textContent = labelText; fieldContainer.appendChild(label); const inputElement = document.createElement("input"); inputElement.type = "number"; inputElement.size = 8; fieldContainer.appendChild(inputElement); root.appendChild(fieldContainer); } const fields = document.createElement("div"); fields.style.display = "flex"; fields.style.gap = "1em"; fields.style.alignItems = "end"; const inputGoldPerfect = createFormField(fields, "Gold Perfect"); const inputAnyPerfect = createFormField(fields, "Any Perfect"); const inputGreat = createFormField(fields, "Great"); const inputGood = createFormField(fields, "Good"); const inputMiss = createFormField(fields, "Miss"); const calculateBtn = document.createElement("button"); calculateBtn.textContent = "Calculate"; fields.appendChild(calculateBtn); root.appendChild(fields); 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}`; }); });