MediaWiki:TeamBingo.js: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
No edit summary |
||
| Line 1: | Line 1: | ||
// --- Team Bingo Board with Fixed Info Box --- | // --- Team Bingo Board with Fixed Info Box & Captain Restriction --- | ||
mw.hook('wikipage.content').add(function () { | mw.hook('wikipage.content').add(function () { | ||
var containers = document.querySelectorAll(".teamBingoContainer"); | var containers = document.querySelectorAll(".teamBingoContainer"); | ||
if (!containers.length) return; | if (!containers.length) return; | ||
| Line 12: | Line 11: | ||
container.innerHTML = ""; | container.innerHTML = ""; | ||
// | // Captain username from attribute | ||
var captain = container.getAttribute("data-captain"); | var captain = container.getAttribute("data-captain"); | ||
// Parse items | // Parse items | ||
var itemsAttr = container.getAttribute("data-items"); | var itemsAttr = container.getAttribute("data-items"); | ||
if (!itemsAttr) return; | if (!itemsAttr) return; | ||
| Line 41: | Line 40: | ||
var cols = Math.ceil(parsedItems.length / rows); | var cols = Math.ceil(parsedItems.length / rows); | ||
// | // API call for images | ||
var allTemplates = parsedItems.map(item => `{{plinkp|${item.name}}}`).join("\n"); | var allTemplates = parsedItems.map(item => `{{plinkp|${item.name}}}`).join("\n"); | ||
$.getJSON("/api.php", { | $.getJSON("/api.php", { | ||
| Line 55: | Line 54: | ||
for (let r = 0; r < rows; r++) { | for (let r = 0; r < rows; r++) { | ||
let row = table.insertRow(); | |||
for (let c = 0; c < cols; c++) { | for (let c = 0; c < cols; c++) { | ||
let index = r * cols + c; | let index = r * cols + c; | ||
| Line 78: | Line 77: | ||
cell.id = id; | cell.id = id; | ||
// Container | // Container | ||
let cellContainer = document.createElement("div"); | let cellContainer = document.createElement("div"); | ||
cellContainer.style.position = "relative"; | cellContainer.style.position = "relative"; | ||
| Line 103: | Line 102: | ||
cellContainer.appendChild(nameDiv); | cellContainer.appendChild(nameDiv); | ||
// Checkmark | // Checkmark | ||
let checkmark = document.createElement("div"); | let checkmark = document.createElement("div"); | ||
checkmark.textContent = "✔"; | checkmark.textContent = "✔"; | ||
| Line 116: | Line 115: | ||
cellContainer.appendChild(checkmark); | cellContainer.appendChild(checkmark); | ||
// Hover | // Hover | ||
cell.addEventListener("mouseenter", function() { | cell.addEventListener("mouseenter", function() { | ||
if (localStorage.getItem(this.id) !== "true") | if (localStorage.getItem(this.id) !== "true") this.style.background = "#3b4a6b"; | ||
infoBox.innerHTML = ""; | infoBox.innerHTML = ""; | ||
let header = document.createElement("div"); | let header = document.createElement("div"); | ||
| Line 129: | Line 124: | ||
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"); | let hoverImg = document.createElement("img"); | ||
| Line 140: | Line 133: | ||
infoBox.appendChild(hoverImg); | infoBox.appendChild(hoverImg); | ||
} | } | ||
item.tooltip.split("%%").forEach(line => { | item.tooltip.split("%%").forEach(line => { | ||
let div = document.createElement("div"); | let div = document.createElement("div"); | ||
| Line 148: | Line 139: | ||
}); | }); | ||
}); | }); | ||
cell.addEventListener("mouseleave", function() { | cell.addEventListener("mouseleave", function() { | ||
if (localStorage.getItem(this.id) !== "true") | if (localStorage.getItem(this.id) !== "true") this.style.background = "#313e59"; | ||
// restore default info | |||
infoBox.innerHTML = defaultInfo(); | |||
infoBox.innerHTML = | |||
}); | }); | ||
// Click | // Click (captain only) | ||
cell.addEventListener("click", function() { | cell.addEventListener("click", function() { | ||
if (mw.config.get('wgUserName') !== captain) return; // only captain | |||
let done = localStorage.getItem(this.id) === "true"; | let done = localStorage.getItem(this.id) === "true"; | ||
localStorage.setItem(this.id, !done); | localStorage.setItem(this.id, !done); | ||
| Line 187: | Line 165: | ||
} | } | ||
// Progress | // Progress | ||
let progressDiv = document.createElement("div"); | let progressDiv = document.createElement("div"); | ||
progressDiv.style.marginTop = "10px"; | progressDiv.style.marginTop = "10px"; | ||
| Line 194: | Line 172: | ||
container.appendChild(progressDiv); | container.appendChild(progressDiv); | ||
// Reset | // Reset | ||
let resetBtn = document.createElement("button"); | let resetBtn = document.createElement("button"); | ||
resetBtn.textContent = "Reset Bingo"; | resetBtn.textContent = "Reset Bingo"; | ||
resetBtn.style.marginTop = "5px"; | resetBtn.style.marginTop = "5px"; | ||
resetBtn.style.cursor = "pointer"; | resetBtn.style.cursor = "pointer"; | ||
resetBtn.addEventListener("click", function () { | resetBtn.addEventListener("click", function () { | ||
if (mw.config.get('wgUserName') !== captain) return; // only captain | |||
for (let i = 0; i < parsedItems.length; i++) { | for (let i = 0; i < parsedItems.length; i++) { | ||
let cb = document.getElementById(`${container.id}_cell_${i}`); | let cb = document.getElementById(`${container.id}_cell_${i}`); | ||
| Line 212: | Line 190: | ||
updateProgress(container, parsedItems.length); | updateProgress(container, parsedItems.length); | ||
}); | }); | ||
container.appendChild(resetBtn); | |||
updateProgress(container, parsedItems.length); | updateProgress(container, parsedItems.length); | ||
}); | }); | ||
function updateProgress(container, total) { | function updateProgress(container, total) { | ||
let completed = 0; | let completed = 0; | ||
| Line 227: | Line 204: | ||
if (progressDiv) | if (progressDiv) | ||
progressDiv.textContent = `Completed ${completed} of ${total} items`; | 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>. | |||
`; | |||
} | } | ||
}); | }); | ||
}); | }); | ||
Revision as of 15:41, 7 March 2026
// --- Team Bingo Board with Fixed Info Box & Captain Restriction ---
mw.hook('wikipage.content').add(function () {
var containers = document.querySelectorAll(".teamBingoContainer");
if (!containers.length) return;
// Shared info box
var infoBox = document.getElementById("teamBingoInfoBox");
containers.forEach(function(container) {
container.innerHTML = "";
// Captain username from attribute
var captain = container.getAttribute("data-captain");
// Parse items
var itemsAttr = container.getAttribute("data-items");
if (!itemsAttr) return;
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 = "100%";
container.appendChild(table);
var rows = Math.ceil(Math.sqrt(parsedItems.length));
var cols = Math.ceil(parsedItems.length / rows);
// API call for 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++) {
let 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
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
let 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.background = "none";
checkmark.style.display = "none";
cellContainer.appendChild(checkmark);
// Hover
cell.addEventListener("mouseenter", function() {
if (localStorage.getItem(this.id) !== "true") this.style.background = "#3b4a6b";
infoBox.innerHTML = "";
let header = document.createElement("div");
header.style.fontWeight = "bold";
header.style.marginBottom = "5px";
header.textContent = item.name;
infoBox.appendChild(header);
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);
}
item.tooltip.split("%%").forEach(line => {
let div = document.createElement("div");
div.innerHTML = line.trim();
infoBox.appendChild(div);
});
});
cell.addEventListener("mouseleave", function() {
if (localStorage.getItem(this.id) !== "true") this.style.background = "#313e59";
// restore default info
infoBox.innerHTML = defaultInfo();
});
// Click (captain only)
cell.addEventListener("click", function() {
if (mw.config.get('wgUserName') !== captain) return; // only captain
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";
}
cell.appendChild(cellContainer);
}
}
// Progress
let progressDiv = document.createElement("div");
progressDiv.style.marginTop = "10px";
progressDiv.style.color = "#fff";
progressDiv.className = "bingoProgress";
container.appendChild(progressDiv);
// Reset
let resetBtn = document.createElement("button");
resetBtn.textContent = "Reset Bingo";
resetBtn.style.marginTop = "5px";
resetBtn.style.cursor = "pointer";
resetBtn.addEventListener("click", function () {
if (mw.config.get('wgUserName') !== captain) return; // only captain
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`;
}
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>.
`;
}
});
});