MediaWiki:Common.js

From The Undead Archive
Revision as of 14:46, 13 June 2026 by TheUnburied (talk | contribs) (Created page with "Any JavaScript here will be loaded for all users on every page load.: (function () { function weightedChoose(container) { const options = [...container.querySelectorAll(".gadget-choose-option")]; const weights = options.map(el => parseFloat(el.dataset.weight ?? 1)); const total = weights.reduce((sum, w) => sum + w, 0); let random = Math.random() * total; const chosen = options.find((_el, i) => (random -= weights[i]) < 0)...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

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)
  • Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5.
/* Any JavaScript here will be loaded for all users on every page load. */
(function () {
    function weightedChoose(container) {
        const options = [...container.querySelectorAll(".gadget-choose-option")];

        const weights = options.map(el => parseFloat(el.dataset.weight ?? 1));
        const total = weights.reduce((sum, w) => sum + w, 0);

        let random = Math.random() * total;
        const chosen = options.find((_el, i) => (random -= weights[i]) < 0);

        options.forEach(el => el.style.display = "none");
        chosen.style.display = "";
    }

    document.querySelectorAll(".gadget-choose").forEach(weightedChoose);
})();