MediaWiki:TeamBingo.js: Difference between revisions

From Roat Pkz
Jump to navigation Jump to search
No edit summary
No edit summary
 
(43 intermediate revisions by the same user not shown)
Line 1: Line 1:
// --- Team Bingo Board with Fixed Info Box & Captain Restriction ---
// --- Team Bingo Board with Captains and Refresh ---
mw.hook('wikipage.content').add(function () {
mw.hook('wikipage.content').add(function () {


     var containers = document.querySelectorAll(".teamBingoContainer");
     const currentUser = mw.config.get('wgUserName'); // logged-in user
    const containers = document.querySelectorAll(".teamBingoContainer");
     if (!containers.length) return;
     if (!containers.length) return;


     // Shared info box
     // Shared info box
     var infoBox = document.getElementById("teamBingoInfoBox");
     const infoBox = document.getElementById("teamBingoInfoBox");


     containers.forEach(function(container) {
     // Default info box content
    const defaultInfoHTML = `
<div style="text-align: center; font-weight: bold; font-size: 16px; margin-bottom: 8px;">
  Team Bingo Challenge
</div>
Welcome to the <strong>Roat Pkz Team Bingo #3</strong> event. Each team has its own bingo board — your goal is to collect the drops or items listed on your team’s board to score points. Each completed tile = 1 point.<br><br>
 
<strong>Rules:</strong><br>
- Only <strong>team captains</strong> can mark tiles for their team.<br>
- Your board updates <strong>when you click Refresh Board</strong>.<br>
- Screenshots of drops/items are required for verification.<br>
- Chests, crates, and boxes do <em>not</em> count.<br><br>
 
<strong>Event ends:</strong> June 28th, 11:59 PM GMT<br><br>
 
<strong>Rewards:</strong><br>
- 500 CREDITS (25M+) — 1st place<br>
- 300 CREDITS (15M+) — 2nd place<br>
- 200 CREDITS (10M+) — 3rd place<br><br>
`;
 
    infoBox.innerHTML = defaultInfoHTML;
 
    const boardState = {}; // central source of truth for all tiles
 
    // Fetch JSON from Module page
    function fetchBoardData(callback) {
        $.getJSON(mw.util.wikiScript('api'), {
            action: 'query',
            titles: 'Module:TeamBingo/data.json',
            prop: 'revisions',
            rvprop: 'content',
            format: 'json',
            formatversion: 2
        }).done(function(data){
            if (!data.query.pages[0].revisions) return;
            const content = data.query.pages[0].revisions[0].content;
            try {
                const json = JSON.parse(content);
                Object.assign(boardState, json); // update central state
                callback(boardState);
            } catch(e) {
                console.error("Failed to parse JSON from Module:TeamBingo/data.json", e);
            }
        });
    }
 
    // Render the board
    function renderBoard(container, teamKey) {
         container.innerHTML = "";
         container.innerHTML = "";


         // Captain username from attribute
         // --- Team Name ---
         var captain = container.getAttribute("data-captain");
         const teamNameDiv = document.createElement("div");
        teamNameDiv.textContent = container.getAttribute("data-team") === "teamA" ? "Team A" : "Team B";
        teamNameDiv.style.fontWeight = "bold";
        teamNameDiv.style.fontSize = "18px";
        teamNameDiv.style.color = "#fff";
        teamNameDiv.style.textAlign = "center";
        teamNameDiv.style.marginBottom = "5px";
        container.appendChild(teamNameDiv);
        // --- END TEAM NAME ---
 
        // --- Refresh Button ---
        const refreshBtn = document.createElement("button");
        refreshBtn.textContent = "Refresh Board";
        refreshBtn.style.display = "block";
        refreshBtn.style.margin = "5px auto 15px auto";
        refreshBtn.style.padding = "6px 12px";
        refreshBtn.style.fontSize = "14px";
        refreshBtn.style.cursor = "pointer";
        refreshBtn.style.borderRadius = "4px";
        refreshBtn.style.border = "1px solid #596e96";
        refreshBtn.style.backgroundColor = "#3b4a6b";
        refreshBtn.style.color = "#fff";
        refreshBtn.addEventListener("click", function() {
            fetchBoardData(function(boardData){
                renderBoard(container, teamKey);
            });
        });
        container.appendChild(refreshBtn);
        // --- END Refresh Button ---


         // Parse items
         const itemsAttr = container.getAttribute("data-items");
        var itemsAttr = container.getAttribute("data-items");
         if (!itemsAttr) return;
         if (!itemsAttr) return;
         var items = itemsAttr.split("|").filter(i => i.trim() !== "");
 
         const items = itemsAttr.split("|").filter(i => i.trim() !== "");
         if (!items.length) return;
         if (!items.length) return;


         var parsedItems = items.map(entry => {
         const parsedItems = items.map(entry => {
             var parts = entry.split("::");
             const parts = entry.split("::");
             return {
             return { name: parts[0].trim(), tooltip: parts[1] ? parts[1].trim() : parts[0].trim() };
                name: parts[0].trim(),
                tooltip: parts[1] ? parts[1].trim() : parts[0].trim()
            };
         });
         });


         // Build table
         const table = document.createElement("table");
        var table = document.createElement("table");
         table.style.tableLayout = "fixed";
         table.style.tableLayout = "fixed";
         table.style.border = "2px solid #596e96";
         table.style.border = "2px solid #596e96";
Line 37: Line 110:
         container.appendChild(table);
         container.appendChild(table);


         var rows = Math.ceil(Math.sqrt(parsedItems.length));
         const rows = Math.ceil(Math.sqrt(parsedItems.length));
         var cols = Math.ceil(parsedItems.length / rows);
         const cols = Math.ceil(parsedItems.length / rows);


         // API call for images
         const allTemplates = parsedItems.map(item => `{{plinkp|${item.name}}}`).join("\n");
        var allTemplates = parsedItems.map(item => `{{plinkp|${item.name}}}`).join("\n");
         $.getJSON("/api.php", { action: "parse", text: allTemplates, format: "json" }).done(function(data) {
         $.getJSON("/api.php", {
            action: "parse",
            text: allTemplates,
            format: "json"
        }).done(function(data) {
             if (!data.parse || !data.parse.text) return;
             if (!data.parse || !data.parse.text) return;
 
             const tempDiv = document.createElement("div");
             var tempDiv = document.createElement("div");
             tempDiv.innerHTML = data.parse.text["*"];
             tempDiv.innerHTML = data.parse.text["*"];
             var imgs = tempDiv.querySelectorAll("img");
             const imgs = tempDiv.querySelectorAll("img");


             for (let r = 0; r < rows; r++) {
             for (let r = 0; r < rows; r++) {
                 let row = table.insertRow();
                 const row = table.insertRow();
                 for (let c = 0; c < cols; c++) {
                 for (let c = 0; c < cols; c++) {
                     let index = r * cols + c;
                     const index = r * cols + c;
                     if (index >= parsedItems.length) break;
                     if (index >= parsedItems.length) break;


                     let item = parsedItems[index];
                     const item = parsedItems[index];
                     let cell = row.insertCell();
                     const cell = row.insertCell();
                     cell.style.width = `${100 / cols}%`;
                     cell.style.width = `${100 / cols}%`;
                     cell.style.padding = "10px";
                     cell.style.padding = "10px";
                     cell.style.border = "1px solid #596e96";
                     cell.style.border = "1px solid #596e96";
                     cell.style.textAlign = "center";
                     cell.style.textAlign = "center";
                     cell.style.background = "#313e59";
                     cell.style.background = boardState[teamKey][`tile_${index}`] ? "rgba(76,175,80,0.5)" : "#313e59";
                     cell.style.color = "#fff";
                     cell.style.color = "#fff";
                     cell.style.cursor = "pointer";
                     cell.style.cursor = "pointer";
                     cell.style.transition = "all 0.2s ease";
                     cell.style.transition = "all 0.2s ease";
                    cell.style.position = "relative";
                     cell.style.userSelect = "none";
                     cell.style.userSelect = "none";
                    cell.style.wordWrap = "break-word";
                    cell.style.overflow = "visible";
                    cell.style.position = "relative";


                     let id = `${container.id}_cell_${index}`;
                     const cellContainer = document.createElement("div");
                    cell.id = id;
 
                    // Container
                    let cellContainer = document.createElement("div");
                     cellContainer.style.position = "relative";
                     cellContainer.style.position = "relative";
                     cellContainer.style.width = "100%";
                     cellContainer.style.width = "100%";
                     cellContainer.style.height = "100%";
                     cellContainer.style.height = "100%";


                     // Image
                     // Item Image
                     if (imgs[index]) {
                     if (imgs[index]) {
                         let img = document.createElement("img");
                         const img = document.createElement("img");
                         img.src = imgs[index].src;
                         img.src = imgs[index].src;
                         img.alt = item.name;
                         img.alt = item.name;
Line 95: Line 156:
                     }
                     }


                     // Name
                     // Item Name
                     let nameDiv = document.createElement("div");
                     const nameDiv = document.createElement("div");
                     nameDiv.textContent = item.name;
                     nameDiv.textContent = item.name;
                     nameDiv.style.marginTop = "5px";
                     nameDiv.style.marginTop = "5px";
Line 103: Line 164:


                     // Checkmark
                     // Checkmark
                     let checkmark = document.createElement("div");
                     const checkmark = document.createElement("div");
                     checkmark.textContent = "✔";
                     checkmark.textContent = "✔";
                     checkmark.className = "bingoCheckmark";
                     checkmark.className = "bingoCheckmark";
Line 111: Line 172:
                     checkmark.style.fontSize = "20px";
                     checkmark.style.fontSize = "20px";
                     checkmark.style.color = "#4CAF50";
                     checkmark.style.color = "#4CAF50";
                     checkmark.style.background = "none";
                     checkmark.style.display = boardState[teamKey][`tile_${index}`] ? "block" : "none";
                    checkmark.style.display = "none";
                     cellContainer.appendChild(checkmark);
                     cellContainer.appendChild(checkmark);


                     // Hover
                     // Hover info with images and tooltip lines
                     cell.addEventListener("mouseenter", function() {
                     cell.addEventListener("mouseenter", function() {
                         if (localStorage.getItem(this.id) !== "true") this.style.background = "#3b4a6b";
                         if (!boardState[teamKey][`tile_${index}`]) cell.style.background = "#3b4a6b";
                         infoBox.innerHTML = "";
                         infoBox.innerHTML = "";
                         let header = document.createElement("div");
                         const header = document.createElement("div");
                         header.style.fontWeight = "bold";
                         header.style.fontWeight = "bold";
                         header.style.marginBottom = "5px";
                         header.style.marginBottom = "5px";
                         header.textContent = item.name;
                         header.textContent = item.name;
                         infoBox.appendChild(header);
                         infoBox.appendChild(header);
                         if (imgs[index]) {
                         if (imgs[index]) {
                             let hoverImg = document.createElement("img");
                             const hoverImg = document.createElement("img");
                             hoverImg.src = imgs[index].src;
                             hoverImg.src = imgs[index].src;
                             hoverImg.style.width = "40px";
                             hoverImg.style.width = "40px";
Line 133: Line 194:
                             infoBox.appendChild(hoverImg);
                             infoBox.appendChild(hoverImg);
                         }
                         }
                        // Support multiple lines with %% as <br>
                         item.tooltip.split("%%").forEach(line => {
                         item.tooltip.split("%%").forEach(line => {
                             let div = document.createElement("div");
                             const div = document.createElement("div");
                             div.innerHTML = line.trim();
                             div.innerHTML = line.trim();
                             infoBox.appendChild(div);
                             infoBox.appendChild(div);
                         });
                         });
                     });
                     });
                     cell.addEventListener("mouseleave", function() {
                     cell.addEventListener("mouseleave", function() {
                         if (localStorage.getItem(this.id) !== "true") this.style.background = "#313e59";
                         cell.style.background = boardState[teamKey][`tile_${index}`] ? "rgba(76,175,80,0.5)" : "#313e59";
                        // restore default info
                         infoBox.innerHTML = defaultInfoHTML;
                         infoBox.innerHTML = defaultInfo();
                     });
                     });


                     // Click (captain only)
                     // Click to toggle (captains only)
                     cell.addEventListener("click", function() {
                     cell.addEventListener("click", function() {
                         if (mw.config.get('wgUserName') !== captain) return; // only captain
                         const captainList = container.getAttribute("data-captain").split(",").map(u => u.trim());
                         let done = localStorage.getItem(this.id) === "true";
                         if (!captainList.includes(currentUser)) return;
                         localStorage.setItem(this.id, !done);
                         const done = boardState[teamKey][`tile_${index}`];
                         this.style.background = !done ? "rgba(76,175,80,0.5)" : "#313e59";
                         boardState[teamKey][`tile_${index}`] = !done;
                         checkmark.style.display = !done ? "block" : "none";
                         checkmark.style.display = !done ? "block" : "none";
                         updateProgress(container, parsedItems.length);
                         cell.style.background = !done ? "rgba(76,175,80,0.5)" : "#313e59";
 
                        // Save to MediaWiki
                        $.post(mw.util.wikiScript('api'), {
                            action: 'edit',
                            title: 'Module:TeamBingo/data.json',
                            token: mw.user.tokens.get('csrfToken'),
                            format: 'json',
                            text: JSON.stringify(boardState, null, 4)
                        }).done(() => console.log("Board updated for everyone!"));
                     });
                     });
                    // Load saved state
                    if (localStorage.getItem(id) === "true") {
                        cell.style.background = "rgba(76,175,80,0.5)";
                        checkmark.style.display = "block";
                    }


                     cell.appendChild(cellContainer);
                     cell.appendChild(cellContainer);
Line 165: Line 231:
             }
             }


            // Progress
// Progress
            let progressDiv = document.createElement("div");
const progressDiv = document.createElement("div");
            progressDiv.style.marginTop = "10px";
progressDiv.style.marginTop = "10px";
            progressDiv.style.color = "#fff";
progressDiv.style.color = "#fff";
            progressDiv.className = "bingoProgress";
progressDiv.style.textAlign = "center"; // <-- center the text
            container.appendChild(progressDiv);
progressDiv.className = "bingoProgress";
container.appendChild(progressDiv);


            // Reset
function updateProgress() {
            let resetBtn = document.createElement("button");
    let completed = 0;
            resetBtn.textContent = "Reset Bingo";
    for (let i = 0; i < parsedItems.length; i++)
            resetBtn.style.marginTop = "5px";
        if (boardState[teamKey][`tile_${i}`]) completed++;
            resetBtn.style.cursor = "pointer";
    progressDiv.textContent = `Completed ${completed} of ${parsedItems.length} items`;
            resetBtn.addEventListener("click", function () {
}
                if (mw.config.get('wgUserName') !== captain) return; // only captain
updateProgress();
                for (let i = 0; i < parsedItems.length; i++) {
        });
                    let cb = document.getElementById(`${container.id}_cell_${i}`);
    }
                    if (cb) {
                        localStorage.setItem(cb.id, false);
                        cb.style.background = "#313e59";
                        let check = cb.querySelector(".bingoCheckmark");
                        if (check) check.style.display = "none";
                    }
                }
                updateProgress(container, parsedItems.length);
            });
            container.appendChild(resetBtn);


             updateProgress(container, parsedItems.length);
    // Initial render
    fetchBoardData(function(boardData){
        containers.forEach(container => {
             const teamKey = container.getAttribute("data-team");
            renderBoard(container, teamKey);
         });
         });
    });


        function updateProgress(container, total) {
            let completed = 0;
            for (let i = 0; i < total; i++) {
                let cb = document.getElementById(`${container.id}_cell_${i}`);
                if (cb && localStorage.getItem(cb.id) === "true") completed++;
            }
            let progressDiv = container.querySelector(".bingoProgress");
            if (progressDiv)
                progressDiv.textContent = `Completed ${completed} of ${total} items`;
        }
        function defaultInfo() {
            return `
<strong>Roat Pkz PVM Bingo #3</strong><br>
Collect drops from PVM or skilling to score points — each drop = 1 point. Screenshots required; no chests, crates, or boxes. Event ends <strong>June 28th, 11:59 PM GMT</strong>.<br><br>
<strong>Rewards:</strong><br>
- 500 CREDITS (25M+)<br>
- 300 CREDITS (15M+)<br>
- 200 CREDITS (10M+)<br><br>
Only drops <strong>after this announcement</strong> count. Submit sheets via the <strong>No Access</strong> channel or message <strong>@JAY</strong>.
            `;
        }
    });
});
});

Latest revision as of 18:03, 7 March 2026

// --- Team Bingo Board with Captains and Refresh ---
mw.hook('wikipage.content').add(function () {

    const currentUser = mw.config.get('wgUserName'); // logged-in user
    const containers = document.querySelectorAll(".teamBingoContainer");
    if (!containers.length) return;

    // Shared info box
    const infoBox = document.getElementById("teamBingoInfoBox");

    // Default info box content
    const defaultInfoHTML = `
<div style="text-align: center; font-weight: bold; font-size: 16px; margin-bottom: 8px;">
  Team Bingo Challenge
</div>
Welcome to the <strong>Roat Pkz Team Bingo #3</strong> event. Each team has its own bingo board — your goal is to collect the drops or items listed on your team’s board to score points. Each completed tile = 1 point.<br><br>

<strong>Rules:</strong><br>
- Only <strong>team captains</strong> can mark tiles for their team.<br>
- Your board updates <strong>when you click Refresh Board</strong>.<br>
- Screenshots of drops/items are required for verification.<br>
- Chests, crates, and boxes do <em>not</em> count.<br><br>

<strong>Event ends:</strong> June 28th, 11:59 PM GMT<br><br>

<strong>Rewards:</strong><br>
- 500 CREDITS (25M+) — 1st place<br>
- 300 CREDITS (15M+) — 2nd place<br>
- 200 CREDITS (10M+) — 3rd place<br><br>
`;

    infoBox.innerHTML = defaultInfoHTML;

    const boardState = {}; // central source of truth for all tiles

    // Fetch JSON from Module page
    function fetchBoardData(callback) {
        $.getJSON(mw.util.wikiScript('api'), {
            action: 'query',
            titles: 'Module:TeamBingo/data.json',
            prop: 'revisions',
            rvprop: 'content',
            format: 'json',
            formatversion: 2
        }).done(function(data){
            if (!data.query.pages[0].revisions) return;
            const content = data.query.pages[0].revisions[0].content;
            try {
                const json = JSON.parse(content);
                Object.assign(boardState, json); // update central state
                callback(boardState);
            } catch(e) {
                console.error("Failed to parse JSON from Module:TeamBingo/data.json", e);
            }
        });
    }

    // Render the board
    function renderBoard(container, teamKey) {
        container.innerHTML = "";

        // --- Team Name ---
        const teamNameDiv = document.createElement("div");
        teamNameDiv.textContent = container.getAttribute("data-team") === "teamA" ? "Team A" : "Team B";
        teamNameDiv.style.fontWeight = "bold";
        teamNameDiv.style.fontSize = "18px";
        teamNameDiv.style.color = "#fff";
        teamNameDiv.style.textAlign = "center";
        teamNameDiv.style.marginBottom = "5px";
        container.appendChild(teamNameDiv);
        // --- END TEAM NAME ---

        // --- Refresh Button ---
        const refreshBtn = document.createElement("button");
        refreshBtn.textContent = "Refresh Board";
        refreshBtn.style.display = "block";
        refreshBtn.style.margin = "5px auto 15px auto";
        refreshBtn.style.padding = "6px 12px";
        refreshBtn.style.fontSize = "14px";
        refreshBtn.style.cursor = "pointer";
        refreshBtn.style.borderRadius = "4px";
        refreshBtn.style.border = "1px solid #596e96";
        refreshBtn.style.backgroundColor = "#3b4a6b";
        refreshBtn.style.color = "#fff";
        refreshBtn.addEventListener("click", function() {
            fetchBoardData(function(boardData){
                renderBoard(container, teamKey);
            });
        });
        container.appendChild(refreshBtn);
        // --- END Refresh Button ---

        const itemsAttr = container.getAttribute("data-items");
        if (!itemsAttr) return;

        const items = itemsAttr.split("|").filter(i => i.trim() !== "");
        if (!items.length) return;

        const parsedItems = items.map(entry => {
            const parts = entry.split("::");
            return { name: parts[0].trim(), tooltip: parts[1] ? parts[1].trim() : parts[0].trim() };
        });

        const table = document.createElement("table");
        table.style.tableLayout = "fixed";
        table.style.border = "2px solid #596e96";
        table.style.borderCollapse = "collapse";
        table.style.borderRadius = "8px";
        table.style.width = "100%";
        container.appendChild(table);

        const rows = Math.ceil(Math.sqrt(parsedItems.length));
        const cols = Math.ceil(parsedItems.length / rows);

        const allTemplates = parsedItems.map(item => `{{plinkp|${item.name}}}`).join("\n");
        $.getJSON("/api.php", { action: "parse", text: allTemplates, format: "json" }).done(function(data) {
            if (!data.parse || !data.parse.text) return;
            const tempDiv = document.createElement("div");
            tempDiv.innerHTML = data.parse.text["*"];
            const imgs = tempDiv.querySelectorAll("img");

            for (let r = 0; r < rows; r++) {
                const row = table.insertRow();
                for (let c = 0; c < cols; c++) {
                    const index = r * cols + c;
                    if (index >= parsedItems.length) break;

                    const item = parsedItems[index];
                    const cell = row.insertCell();
                    cell.style.width = `${100 / cols}%`;
                    cell.style.padding = "10px";
                    cell.style.border = "1px solid #596e96";
                    cell.style.textAlign = "center";
                    cell.style.background = boardState[teamKey][`tile_${index}`] ? "rgba(76,175,80,0.5)" : "#313e59";
                    cell.style.color = "#fff";
                    cell.style.cursor = "pointer";
                    cell.style.transition = "all 0.2s ease";
                    cell.style.position = "relative";
                    cell.style.userSelect = "none";

                    const cellContainer = document.createElement("div");
                    cellContainer.style.position = "relative";
                    cellContainer.style.width = "100%";
                    cellContainer.style.height = "100%";

                    // Item Image
                    if (imgs[index]) {
                        const img = document.createElement("img");
                        img.src = imgs[index].src;
                        img.alt = item.name;
                        img.style.width = "40px";
                        img.style.height = "auto";
                        img.style.display = "block";
                        img.style.margin = "0 auto";
                        cellContainer.appendChild(img);
                    }

                    // Item Name
                    const nameDiv = document.createElement("div");
                    nameDiv.textContent = item.name;
                    nameDiv.style.marginTop = "5px";
                    nameDiv.style.pointerEvents = "none";
                    cellContainer.appendChild(nameDiv);

                    // Checkmark
                    const checkmark = document.createElement("div");
                    checkmark.textContent = "✔";
                    checkmark.className = "bingoCheckmark";
                    checkmark.style.position = "absolute";
                    checkmark.style.top = "2px";
                    checkmark.style.right = "2px";
                    checkmark.style.fontSize = "20px";
                    checkmark.style.color = "#4CAF50";
                    checkmark.style.display = boardState[teamKey][`tile_${index}`] ? "block" : "none";
                    cellContainer.appendChild(checkmark);

                    // Hover info with images and tooltip lines
                    cell.addEventListener("mouseenter", function() {
                        if (!boardState[teamKey][`tile_${index}`]) cell.style.background = "#3b4a6b";
                        infoBox.innerHTML = "";
                        const header = document.createElement("div");
                        header.style.fontWeight = "bold";
                        header.style.marginBottom = "5px";
                        header.textContent = item.name;
                        infoBox.appendChild(header);

                        if (imgs[index]) {
                            const hoverImg = document.createElement("img");
                            hoverImg.src = imgs[index].src;
                            hoverImg.style.width = "40px";
                            hoverImg.style.height = "auto";
                            hoverImg.style.display = "block";
                            hoverImg.style.marginBottom = "5px";
                            infoBox.appendChild(hoverImg);
                        }

                        // Support multiple lines with %% as <br>
                        item.tooltip.split("%%").forEach(line => {
                            const div = document.createElement("div");
                            div.innerHTML = line.trim();
                            infoBox.appendChild(div);
                        });
                    });

                    cell.addEventListener("mouseleave", function() {
                        cell.style.background = boardState[teamKey][`tile_${index}`] ? "rgba(76,175,80,0.5)" : "#313e59";
                        infoBox.innerHTML = defaultInfoHTML;
                    });

                    // Click to toggle (captains only)
                    cell.addEventListener("click", function() {
                        const captainList = container.getAttribute("data-captain").split(",").map(u => u.trim());
                        if (!captainList.includes(currentUser)) return;
                        const done = boardState[teamKey][`tile_${index}`];
                        boardState[teamKey][`tile_${index}`] = !done;
                        checkmark.style.display = !done ? "block" : "none";
                        cell.style.background = !done ? "rgba(76,175,80,0.5)" : "#313e59";

                        // Save to MediaWiki
                        $.post(mw.util.wikiScript('api'), {
                            action: 'edit',
                            title: 'Module:TeamBingo/data.json',
                            token: mw.user.tokens.get('csrfToken'),
                            format: 'json',
                            text: JSON.stringify(boardState, null, 4)
                        }).done(() => console.log("Board updated for everyone!"));
                    });

                    cell.appendChild(cellContainer);
                }
            }

// Progress
const progressDiv = document.createElement("div");
progressDiv.style.marginTop = "10px";
progressDiv.style.color = "#fff";
progressDiv.style.textAlign = "center"; // <-- center the text
progressDiv.className = "bingoProgress";
container.appendChild(progressDiv);

function updateProgress() {
    let completed = 0;
    for (let i = 0; i < parsedItems.length; i++)
        if (boardState[teamKey][`tile_${i}`]) completed++;
    progressDiv.textContent = `Completed ${completed} of ${parsedItems.length} items`;
}
updateProgress();
        });
    }

    // Initial render
    fetchBoardData(function(boardData){
        containers.forEach(container => {
            const teamKey = container.getAttribute("data-team");
            renderBoard(container, teamKey);
        });
    });

});