User:Uraxys/scripts/test.js
From Idle Clans wiki
Note: After publishing, you may have to bypass your browser's cache to see the changes.
- Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
- Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
- Internet Explorer / Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5
- Opera: Press Ctrl-F5.
;(function ($, mw) { const XP_TABLE = [ 0, 100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 1100, 1200, 1300, 1400, 1500, 1600, 1700, 1800, 1900, 2000, 2100, 2200, 2300, 2400, 2500, 2600, 2700, 2800, 2900, 3000, 3100, 3200, 3300, 3400, 3500, 3600, 3700, 3800, 3900, 4000, 4100, 4200, 4300, 4400, 4500, 4600, 4700, 4800, 4900, 5000, 5100, 5200, 5300, 5400, 5500, 5600, 5700, 5800, 5900, 6000, 6100, 6200, 6300, 6400, 6500, 6600, 6700, 6800, 6900, 7000, 7100, 7200, 7300, 7400, 7500, 7600, 7700, 7800, 7900, 8000, 8100, 8200, 8300, 8400, 8500, 8600, 8700, 8800, 8900, 9000, 9100, 9200, 9300, 9400, 9500, 9600, 9700, 9800, 9900, 10000, 10100, 10200, 10300, 10400, 10500, 10600, 10700, 10800, 10900, 11000, 11100, 11200, 11300, 11400, 11500, 11600, 11700, 11800, 11900 ] const $xpCalc = $(".calculator-xp-to-target"); if (!$xpCalc.length) return; const $currentInput = $("<input>", { type: "number", class: "calculator-xp-current", placeholder: "Current Level" }); const $levelToXpText = $("<span>", { text: "XP" }); const $levelToXpSwitch = $("<input>", { type: "checkbox", class: "calculator-xp-switch" }); const $targetInput = $("<input>", { type: "number", class: "calculator-xp-target", placeholder: "Target Level" }); const $calculateButton = $("<button>", { text: "Calculate", class: "calculator-xp-calculate" }); $xpCalc.append( $("<p>").append($currentInput, $levelToXpText, $levelToXpSwitch), $("<p>").append($targetInput), $("<p>").append($calculateButton) ); const $result = $("<p>", { class: "calculator-xp-result" }); $xpCalc.append($result); $calculateButton.click(function() { const current = Number($currentInput.val()); const targetLvl = Number($targetInput.val()); if (isNaN(current) || isNaN(targetLvl)) { $result.text("Invalid input."); return; } if (targetLvl < 1 || targetLvl > 120) { $result.text("Invalid target level."); return; } const isXp = $levelToXpSwitch.prop("checked"); let currentXp = current; if (!isXp) { if (current < 1 || current > 120) { $result.text("Invalid current level."); return; } currentXp = XP_TABLE[current - 1]; } const targetXp = XP_TABLE[targetLvl - 1]; const xpNeeded = targetXp - currentXp; if (xpNeeded <= 0) { $result.text("You are already at level " + targetLvl + "."); return; } $result.text("You need " + xpNeeded + " XP to reach level " + targetLvl + ".") }); })(jQuery, mw);