Jump to content

MediaWiki:Common.js

From Shrimp Squad
Revision as of 17:42, 30 March 2026 by Blippy (talk | contribs)

Note: After publishing, you may have to bypass your browser's cache to see the changes.

  • Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
  • Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
  • Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5.
/* 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" });
  });
});