|
|
| Line 1: |
Line 1: |
| /* Any JavaScript here will be loaded for all users on every page load. */ | | /* Any JavaScript here will be loaded for all users on every page load. */ |
| document.addEventListener("DOMContentLoaded", () => {
| |
| const table = document.querySelector(".wikitable.sortable");
| |
| if (!table) return;
| |
|
| |
| const tbody = table.querySelector("tbody");
| |
| if (!tbody) return;
| |
|
| |
| const rows = Array.from(tbody.querySelectorAll("tr")).slice(1); // skip header
| |
|
| |
| // Fisher–Yates shuffle
| |
| for (let i = rows.length - 1; i > 0; i--) {
| |
| const j = Math.floor(Math.random() * (i + 1));
| |
| [rows[i], rows[j]] = [rows[j], rows[i]];
| |
| }
| |
|
| |
| // Re-append in shuffled order
| |
| rows.forEach(row => tbody.appendChild(row));
| |
| });
| |
|
| |
| document.addEventListener("DOMContentLoaded", () => {
| |
| const table = document.querySelector(".wikitable.sortable");
| |
| if (!table) return;
| |
|
| |
| const tbody = table.querySelector("tbody");
| |
| const rows = Array.from(tbody.querySelectorAll("tr")).slice(1);
| |
|
| |
| // Create button
| |
| const button = document.createElement("button");
| |
| button.textContent = "🎲 Pick Random Game";
| |
| button.style.marginBottom = "10px";
| |
| button.style.padding = "8px 12px";
| |
| button.style.cursor = "pointer";
| |
|
| |
| table.parentNode.insertBefore(button, table);
| |
|
| |
| button.addEventListener("click", () => {
| |
| // Clear previous highlights
| |
| rows.forEach(r => r.style.background = "");
| |
|
| |
| const randomRow = rows[Math.floor(Math.random() * rows.length)];
| |
|
| |
| // Highlight it
| |
| randomRow.style.background = "#d4edda";
| |
|
| |
| // Scroll into view
| |
| randomRow.scrollIntoView({ behavior: "smooth", block: "center" });
| |
| });
| |
| });
| |