MediaWiki:BingoSheet.js: Difference between revisions

From Roat Pkz
Jump to navigation Jump to search
No edit summary
No edit summary
 
(63 intermediate revisions by the same user not shown)
Line 1: Line 1:
// --- Fixed 600px Bingo Board with Fixed Info Box & Correct Checkmarks ---
mw.hook('wikipage.content').add(function () {
mw.hook('wikipage.content').add(function () {
    var containers = document.querySelectorAll(".bingoContainer");
    if (!containers.length) return;


     // Auto-create container if it doesn't exist
     containers.forEach(function(container) {
    var container = document.getElementById("bingoContainer");
         container.innerHTML = "";
    if (!container) {
         container = document.createElement("div");
        container.id = "bingoContainer";
        container.style.margin = "20px 0";
        document.body.appendChild(container);
    }
    container.innerHTML = ""; // clear container


    var table = document.createElement("table");
        // Wrap board + info box in flex container
    table.style.border = "2px solid #596e96";
        var wrapper = document.createElement("div");
    table.style.borderCollapse = "collapse";
        wrapper.style.display = "flex";
    table.style.borderRadius = "8px";
        wrapper.style.gap = "20px";
    table.style.width = "100%";
        wrapper.style.alignItems = "flex-start";
    table.style.maxWidth = "500px";
        container.parentNode.insertBefore(wrapper, container);
        wrapper.appendChild(container);


    var rows = 5, cols = 5;
        // Create fixed info box
        var infoBox = document.createElement("div");
        infoBox.style.padding = "10px";
        infoBox.style.border = "1px solid #596e96";
        infoBox.style.backgroundColor = "#313e59";
        infoBox.style.color = "#fff";
        infoBox.style.borderRadius = "4px";
        infoBox.style.minWidth = "180px";
        infoBox.style.maxWidth = "220px";
        infoBox.style.whiteSpace = "normal";
        infoBox.style.wordWrap = "break-word";
        infoBox.style.overflow = "visible";
        infoBox.style.transition = "all 0.2s ease";
        infoBox.style.fontSize = "14px";
        infoBox.innerHTML = `
<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.
`;
        wrapper.appendChild(infoBox);


    // Example images array (replace with your wiki image URLs)
         // Parse items: Item Name::Custom Tooltip (use %% for line breaks)
    var images = [
         var itemsAttr = container.getAttribute("data-items");
         "https://wiki.roatpkz.com/images/Item1.png",
         var items = itemsAttr.split("|").filter(i => i.trim() !== "");
        "https://wiki.roatpkz.com/images/Item2.png",
         if (!items.length) return;
        "https://wiki.roatpkz.com/images/Item3.png",
        "https://wiki.roatpkz.com/images/Item4.png",
         "https://wiki.roatpkz.com/images/Item5.png",
        "https://wiki.roatpkz.com/images/Item6.png",
         "https://wiki.roatpkz.com/images/Item7.png",
        "https://wiki.roatpkz.com/images/Item8.png",
        "https://wiki.roatpkz.com/images/Item9.png",
         "https://wiki.roatpkz.com/images/Item10.png",
        "https://wiki.roatpkz.com/images/Item11.png",
        "https://wiki.roatpkz.com/images/Item12.png",
        "https://wiki.roatpkz.com/images/Item13.png",
        "https://wiki.roatpkz.com/images/Item14.png",
        "https://wiki.roatpkz.com/images/Item15.png",
        "https://wiki.roatpkz.com/images/Item16.png",
        "https://wiki.roatpkz.com/images/Item17.png",
        "https://wiki.roatpkz.com/images/Item18.png",
        "https://wiki.roatpkz.com/images/Item19.png",
        "https://wiki.roatpkz.com/images/Item20.png",
        "https://wiki.roatpkz.com/images/Item21.png",
        "https://wiki.roatpkz.com/images/Item22.png",
        "https://wiki.roatpkz.com/images/Item23.png",
        "https://wiki.roatpkz.com/images/Item24.png",
        "https://wiki.roatpkz.com/images/Item25.png"
    ];


    // Create grid
        var parsedItems = items.map(entry => {
    for (var r = 0; r < rows; r++) {
            var parts = entry.split("::");
        var row = table.insertRow();
            return {
        row.style.background = r % 2 === 0 ? "#313e59" : "#222e45";
                name: parts[0].trim(),
                tooltip: parts[1] ? parts[1].trim() : parts[0].trim()
            };
        });


         for (var c = 0; c < cols; c++) {
         // Build table
            var cell = row.insertCell();
        var table = document.createElement("table");
            cell.style.padding = "10px";
        table.style.tableLayout = "fixed";
            cell.style.border = "1px solid #444";
        table.style.border = "2px solid #596e96";
            cell.style.textAlign = "center";
        table.style.borderCollapse = "collapse";
            cell.style.color = "#fff";
        table.style.borderRadius = "8px";
            cell.style.cursor = "pointer";
        table.style.width = "600px"; // fixed width
            cell.style.transition = "opacity 0.3s ease";
        container.appendChild(table);
            cell.style.userSelect = "none"; // prevent text selection


            var id = `cell_${r}_${c}`;
        var rows = Math.ceil(Math.sqrt(parsedItems.length));
        var cols = Math.ceil(parsedItems.length / rows);


            // Image
        // Single API call for all images
            var img = document.createElement("img");
        var allTemplates = parsedItems.map(item => `{{plinkp|${item.name}}}`).join("\n");
            img.src = images[r*cols + c];
        $.getJSON("/api.php", {
            img.alt = `Item ${r*cols+c+1}`;
             action: "parse",
            img.style.width = "40px";
            text: allTemplates,
            img.style.height = "40px";
             format: "json"
             img.style.display = "block";
        }).done(function(data) {
             img.style.margin = "0 auto 5px auto";
             if (!data.parse || !data.parse.text) return;
             cell.appendChild(img);


             // Text label
             var tempDiv = document.createElement("div");
             cell.appendChild(document.createTextNode(` Item ${r*cols+c+1}`));
             tempDiv.innerHTML = data.parse.text["*"];
            var imgs = tempDiv.querySelectorAll("img");


             // Restore state from localStorage
             for (let r = 0; r < rows; r++) {
            if (localStorage.getItem(id) === "true") {
                var row = table.insertRow();
                cell.style.opacity = 0.4;
                for (let c = 0; c < cols; c++) {
            }
                    let index = r * cols + c;
                    if (index >= parsedItems.length) break;
 
                    let item = parsedItems[index];
                    let 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 = "#313e59";
                    cell.style.color = "#fff";
                    cell.style.cursor = "pointer";
                    cell.style.transition = "all 0.2s ease";
                    cell.style.userSelect = "none";
                    cell.style.wordWrap = "break-word";
                    cell.style.overflow = "visible";
                    cell.style.position = "relative";
 
                    let id = `${container.id}_cell_${index}`;
                    cell.id = id;
 
                    // Container for image + name
                    let cellContainer = document.createElement("div");
                    cellContainer.style.position = "relative";
                    cellContainer.style.width = "100%";
                    cellContainer.style.height = "100%";
 
                    // Image
                    if (imgs[index]) {
                        let 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);
                    }
 
                    // Name
                    let nameDiv = document.createElement("div");
                    nameDiv.textContent = item.name;
                    nameDiv.style.marginTop = "5px";
                    nameDiv.style.pointerEvents = "none";
                    cellContainer.appendChild(nameDiv);
 
                    // ✅ Checkmark in top-right of cell
                    let checkmark = document.createElement("div");
                    checkmark.textContent = "✔";
                    checkmark.className = "bingoCheckmark";
                    checkmark.style.position = "absolute";
                    checkmark.style.top = "2px";
                    checkmark.style.right = "6px";
                    checkmark.style.fontSize = "20px";
                    checkmark.style.color = "#4CAF50";
                    checkmark.style.background = "none";
                    checkmark.style.pointerEvents = "none";
                    checkmark.style.zIndex = "10";
                    checkmark.style.display = localStorage.getItem(id) === "true" ? "block" : "none";
                    cell.appendChild(checkmark);
 
                    // Append image + name after checkmark
                    cell.appendChild(cellContainer);
 
                    // Hover shows info in the fixed box
                    cell.addEventListener("mouseenter", function() {
                        if (localStorage.getItem(this.id) !== "true") {
                            this.style.background = "#3b4a6b";
                        }
 
                        infoBox.innerHTML = "";
 
                        // Name header
                        let header = document.createElement("div");
                        header.style.fontWeight = "bold";
                        header.style.marginBottom = "5px";
                        header.textContent = item.name;
                        infoBox.appendChild(header);
 
                        // Image
                        if (imgs[index]) {
                            let 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);
                        }


            // Click to toggle completed
                        // Multi-line tooltip
            cell.addEventListener("click", function () {
                        item.tooltip.split("%%").forEach(line => {
                var done = localStorage.getItem(this.id) === "true";
                            let div = document.createElement("div");
                localStorage.setItem(this.id, !done);
                            div.innerHTML = line.trim();
                this.style.opacity = !done ? 0.4 : 1;
                            infoBox.appendChild(div);
                updateProgress();
                        });
            });
                    });
        }
    }


    container.appendChild(table);
                    // Mouse leave restores default info
                    cell.addEventListener("mouseleave", function() {
                        if (localStorage.getItem(this.id) !== "true") {
                            this.style.background = "#313e59";
                        }
                        infoBox.innerHTML = `
<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.
`;
                    });


    // Progress display
                    // Click toggle complete
    var progressDiv = document.createElement("div");
                    cell.addEventListener("click", function() {
    progressDiv.style.marginTop = "10px";
                        let done = localStorage.getItem(this.id) === "true";
    progressDiv.style.color = "#fff";
                        localStorage.setItem(this.id, !done);
    container.appendChild(progressDiv);
                        this.style.background = !done ? "rgba(76,175,80,0.5)" : "#313e59";
                        checkmark.style.display = !done ? "block" : "none";
                        updateProgress(container, parsedItems.length);
                    });


    // Reset button
                    // Load saved state
    var resetBtn = document.createElement("button");
                    if (localStorage.getItem(id) === "true") {
    resetBtn.textContent = "Reset Bingo";
                        cell.style.background = "rgba(76,175,80,0.5)";
    resetBtn.style.marginTop = "5px";
                        checkmark.style.display = "block";
    resetBtn.style.cursor = "pointer";
                     }
    resetBtn.addEventListener("click", function () {
        for (var r = 0; r < rows; r++) {
            for (var c = 0; c < cols; c++) {
                var cb = document.getElementById(`cell_${r}_${c}`);
                if (cb) {
                    localStorage.setItem(cb.id, false);
                     cb.style.opacity = 1;
                 }
                 }
             }
             }
        }
        updateProgress();
    });
    container.appendChild(resetBtn);


    // Update progress function
            // Progress counter
    function updateProgress() {
            let progressDiv = document.createElement("div");
        var checked = 0;
            progressDiv.style.marginTop = "10px";
        for (var r = 0; r < rows; r++) {
            progressDiv.style.color = "#fff";
             for (var c = 0; c < cols; c++) {
            progressDiv.className = "bingoProgress";
                 var cb = document.getElementById(`cell_${r}_${c}`);
            container.appendChild(progressDiv);
                 if (cb && localStorage.getItem(cb.id) === "true") checked++;
 
            // Reset button
            let resetBtn = document.createElement("button");
            resetBtn.textContent = "Reset Bingo";
            resetBtn.style.marginTop = "5px";
            resetBtn.style.cursor = "pointer";
 
            resetBtn.addEventListener("click", function () {
                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);
        });
 
        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`;
         }
         }
        progressDiv.textContent = `Completed ${checked} of ${rows*cols} items`;
     });
     }
 
    updateProgress();
});
});

Latest revision as of 14:05, 7 March 2026

// --- Fixed 600px Bingo Board with Fixed Info Box & Correct Checkmarks ---
mw.hook('wikipage.content').add(function () {
    var containers = document.querySelectorAll(".bingoContainer");
    if (!containers.length) return;

    containers.forEach(function(container) {
        container.innerHTML = "";

        // Wrap board + info box in flex container
        var wrapper = document.createElement("div");
        wrapper.style.display = "flex";
        wrapper.style.gap = "20px";
        wrapper.style.alignItems = "flex-start";
        container.parentNode.insertBefore(wrapper, container);
        wrapper.appendChild(container);

        // Create fixed info box
        var infoBox = document.createElement("div");
        infoBox.style.padding = "10px";
        infoBox.style.border = "1px solid #596e96";
        infoBox.style.backgroundColor = "#313e59";
        infoBox.style.color = "#fff";
        infoBox.style.borderRadius = "4px";
        infoBox.style.minWidth = "180px";
        infoBox.style.maxWidth = "220px";
        infoBox.style.whiteSpace = "normal";
        infoBox.style.wordWrap = "break-word";
        infoBox.style.overflow = "visible";
        infoBox.style.transition = "all 0.2s ease";
        infoBox.style.fontSize = "14px";
        infoBox.innerHTML = `
<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.
`;
        wrapper.appendChild(infoBox);

        // Parse items: Item Name::Custom Tooltip (use %% for line breaks)
        var itemsAttr = container.getAttribute("data-items");
        var items = itemsAttr.split("|").filter(i => i.trim() !== "");
        if (!items.length) return;

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

        // Build table
        var 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 = "600px"; // fixed width
        container.appendChild(table);

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

        // Single API call for all images
        var 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;

            var tempDiv = document.createElement("div");
            tempDiv.innerHTML = data.parse.text["*"];
            var imgs = tempDiv.querySelectorAll("img");

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

                    let item = parsedItems[index];
                    let 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 = "#313e59";
                    cell.style.color = "#fff";
                    cell.style.cursor = "pointer";
                    cell.style.transition = "all 0.2s ease";
                    cell.style.userSelect = "none";
                    cell.style.wordWrap = "break-word";
                    cell.style.overflow = "visible";
                    cell.style.position = "relative";

                    let id = `${container.id}_cell_${index}`;
                    cell.id = id;

                    // Container for image + name
                    let cellContainer = document.createElement("div");
                    cellContainer.style.position = "relative";
                    cellContainer.style.width = "100%";
                    cellContainer.style.height = "100%";

                    // Image
                    if (imgs[index]) {
                        let 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);
                    }

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

                    // ✅ Checkmark in top-right of cell
                    let checkmark = document.createElement("div");
                    checkmark.textContent = "✔";
                    checkmark.className = "bingoCheckmark";
                    checkmark.style.position = "absolute";
                    checkmark.style.top = "2px";
                    checkmark.style.right = "6px";
                    checkmark.style.fontSize = "20px";
                    checkmark.style.color = "#4CAF50";
                    checkmark.style.background = "none";
                    checkmark.style.pointerEvents = "none";
                    checkmark.style.zIndex = "10";
                    checkmark.style.display = localStorage.getItem(id) === "true" ? "block" : "none";
                    cell.appendChild(checkmark);

                    // Append image + name after checkmark
                    cell.appendChild(cellContainer);

                    // Hover shows info in the fixed box
                    cell.addEventListener("mouseenter", function() {
                        if (localStorage.getItem(this.id) !== "true") {
                            this.style.background = "#3b4a6b";
                        }

                        infoBox.innerHTML = "";

                        // Name header
                        let header = document.createElement("div");
                        header.style.fontWeight = "bold";
                        header.style.marginBottom = "5px";
                        header.textContent = item.name;
                        infoBox.appendChild(header);

                        // Image
                        if (imgs[index]) {
                            let 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);
                        }

                        // Multi-line tooltip
                        item.tooltip.split("%%").forEach(line => {
                            let div = document.createElement("div");
                            div.innerHTML = line.trim();
                            infoBox.appendChild(div);
                        });
                    });

                    // Mouse leave restores default info
                    cell.addEventListener("mouseleave", function() {
                        if (localStorage.getItem(this.id) !== "true") {
                            this.style.background = "#313e59";
                        }
                        infoBox.innerHTML = `
<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.
`;
                    });

                    // Click toggle complete
                    cell.addEventListener("click", function() {
                        let done = localStorage.getItem(this.id) === "true";
                        localStorage.setItem(this.id, !done);
                        this.style.background = !done ? "rgba(76,175,80,0.5)" : "#313e59";
                        checkmark.style.display = !done ? "block" : "none";
                        updateProgress(container, parsedItems.length);
                    });

                    // Load saved state
                    if (localStorage.getItem(id) === "true") {
                        cell.style.background = "rgba(76,175,80,0.5)";
                        checkmark.style.display = "block";
                    }
                }
            }

            // Progress counter
            let progressDiv = document.createElement("div");
            progressDiv.style.marginTop = "10px";
            progressDiv.style.color = "#fff";
            progressDiv.className = "bingoProgress";
            container.appendChild(progressDiv);

            // Reset button
            let resetBtn = document.createElement("button");
            resetBtn.textContent = "Reset Bingo";
            resetBtn.style.marginTop = "5px";
            resetBtn.style.cursor = "pointer";

            resetBtn.addEventListener("click", function () {
                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);
        });

        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`;
        }
    });
});