MediaWiki:Common.js: Difference between revisions

From The Undead Archive
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)..."
 
Blanked the page
Tag: Blanking
 
Line 1: Line 1:
/* 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);
})();

Latest revision as of 15:29, 13 June 2026