MediaWiki:Gadget-HiddenPowerCalculator.js: Difference between revisions

From Squidgy
Jump to navigation Jump to search
No edit summary
No edit summary
Tag: Reverted
Line 1: Line 1:
mw.loader.using(['mediawiki.util', 'jquery'], function () {
mw.loader.using(['mediawiki.util', 'jquery'], function () {
   $(document).ready(function () {
   $(document).ready(function () {
     const container = document.getElementById('hp-calc-container');
     const div = document.createElement("div");
    if (!container) return;
     div.style.border = "2px dashed red";
 
    div.style.padding = "10px";
    container.innerHTML = `
    div.style.margin = "10px";
      <form id="dvForm">
    div.innerHTML = "<strong>The DV Gadget is LOADED and ACTIVE ✅</strong>";
        <label>Attack DV: <input type="number" id="atk" min="0" max="15" required></label><br>
     document.body.appendChild(div);
        <label>Defense DV: <input type="number" id="def" min="0" max="15" required></label><br>
        <label>Speed DV: <input type="number" id="spe" min="0" max="15" required></label><br>
        <label>Special DV: <input type="number" id="spa" min="0" max="15" required></label><br>
        <button type="button" id="calculateBtn">Calculate</button>
      </form>
      <p id="results"></p>
    `;
 
     document.getElementById("calculateBtn").addEventListener("click", function () {
      const atk = parseInt(document.getElementById("atk").value);
      const def = parseInt(document.getElementById("def").value);
      const spe = parseInt(document.getElementById("spe").value);
      const spa = parseInt(document.getElementById("spa").value);
 
      if ([atk, def, spe, spa].some(n => isNaN(n) || n < 0 || n > 15)) {
        document.getElementById("results").innerText = "All values must be between 0 and 15.";
        return;
      }
 
      const hp = ((atk & 1) << 3) | ((def & 1) << 2) | ((spe & 1) << 1) | (spa & 1);
      const typeId = 4 * (atk % 4) + (def % 4);
      const hpTypes = [
        "Fighting", "Flying", "Poison", "Ground", "Rock", "Bug", "Ghost", "Steel",
        "Fire", "Water", "Grass", "Electric", "Psychic", "Ice", "Dragon", "Dark"
      ];
      const hpType = hpTypes[typeId];
      const v = spa >= 8 ? 1 : 0;
      const w = spe >= 8 ? 1 : 0;
      const x = def >= 8 ? 1 : 0;
      const y = atk >= 8 ? 1 : 0;
      const z = spa % 4;
      const power = Math.floor((5 * (v + 2 * w + 4 * x + 8 * y) + z) * 40 / 63);
      const shiny = [2, 3, 6, 7, 10, 11, 14, 15].includes(atk) && def === 10 && spe === 10 && spa === 10;
 
      document.getElementById("results").innerHTML = `
        <strong>HP DV:</strong> ${hp}<br>
        <strong>Hidden Power:</strong> ${hpType} (${power} Power)<br>
        <strong>Shiny:</strong> ${shiny ? "Yes ✨" : "No"}
      `;
     });
   });
   });
});
});

Revision as of 14:05, 14 May 2025

mw.loader.using(['mediawiki.util', 'jquery'], function () {
  $(document).ready(function () {
    const div = document.createElement("div");
    div.style.border = "2px dashed red";
    div.style.padding = "10px";
    div.style.margin = "10px";
    div.innerHTML = "<strong>The DV Gadget is LOADED and ACTIVE ✅</strong>";
    document.body.appendChild(div);
  });
});