MediaWiki:Common.js

From Roat Pkz
Revision as of 02:32, 5 March 2026 by Hefner (talk | contribs)
Jump to navigation Jump to search

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.
// --- COMMON.JS CLEANED AND UPDATED ---

// --- Dropdown-based Tier Assignment ---
mw.loader.using('jquery').then(function () {
    console.log("✅ Dropdown-based Tier Assignment is running");

    document.addEventListener('DOMContentLoaded', function () {
        function moveItemToTier(itemId, tierId) {
            var item = document.getElementById(itemId);
            var targetTier = document.getElementById(tierId);
            if (item && targetTier) {
                targetTier.appendChild(item);
            }
        }

        var selectors = document.querySelectorAll('.tier-selector');
        selectors.forEach(function(sel) {
            sel.addEventListener('change', function () {
                moveItemToTier(this.id, this.value);
            });
        });
    });
});

// --- Bingo JS ---
mw.loader.using('mediawiki.util', function () {
    document.addEventListener("DOMContentLoaded", function () {
        console.log("✅ Bingo JS Loaded");

        var tiles = document.querySelectorAll(".bingo-table td .lighttable-cell");
        tiles.forEach(function(tile) {
            var id = tile.dataset.key || tile.id;
            if (!id) return;

            if (localStorage.getItem(id) === "selected") {
                tile.classList.add("bingo-selected");
            }

            tile.addEventListener("click", function () {
                tile.classList.toggle("bingo-selected");
                if (tile.classList.contains("bingo-selected")) {
                    localStorage.setItem(id, "selected");
                } else {
                    localStorage.removeItem(id);
                }
            });
        });
    });
});

// --- Skill XP Calculator ---
document.addEventListener("DOMContentLoaded", function() {
    var tables = document.querySelectorAll(".skill-info-calc");
    tables.forEach(function(table){
        var xpPerAction = parseInt(table.querySelector("span.total-xp").textContent);
        var numActionsElem = table.querySelector(".num-actions");
        var totalXPElem = table.querySelector(".total-xp");

        table.querySelector(".increase").addEventListener("click", function() {
            var actions = parseInt(numActionsElem.textContent) + 1;
            numActionsElem.textContent = actions;
            totalXPElem.textContent = actions * xpPerAction;
        });

        table.querySelector(".decrease").addEventListener("click", function() {
            var actions = parseInt(numActionsElem.textContent) - 1;
            if (actions < 0) actions = 0;
            numActionsElem.textContent = actions;
            totalXPElem.textContent = actions * xpPerAction;
        });
    });
});

// --- Simple Calculator ---
document.addEventListener("DOMContentLoaded", function() {
    const container = document.getElementById("calcContainer");
    if (!container) return;

    // Build calculator HTML dynamically
    container.innerHTML = `
        <div style="margin:10px 0;">
            <label>Num1: <input type="number" id="num1" value="0" style="width:60px;"></label>
            <label>Num2: <input type="number" id="num2" value="0" style="width:60px;"></label>
            <label>Operation:
                <select id="op">
                    <option value="+">+</option>
                    <option value="-">-</option>
                    <option value="*">*</option>
                    <option value="/">/</option>
                </select>
            </label>
            <button id="calcButton">Calculate</button>
        </div>
        <div>Result: <span id="result">0</span></div>
    `;

    // Add calculator functionality
    const btn = document.getElementById("calcButton");
    btn.addEventListener("click", function() {
        const a = parseFloat(document.getElementById("num1").value);
        const b = parseFloat(document.getElementById("num2").value);
        const op = document.getElementById("op").value;
        let result;

        if (isNaN(a) || isNaN(b)) {
            result = "Enter valid numbers";
        } else {
            switch(op) {
                case "+": result = a + b; break;
                case "-": result = a - b; break;
                case "*": result = a * b; break;
                case "/": result = b !== 0 ? a / b : "∞"; break;
                default: result = "Error";
            }
        }
        document.getElementById("result").textContent = result;
    });
});