MediaWiki:Common.js

From Dragon Ball World Wiki
Revision as of 17:57, 15 December 2024 by Titan099 (talk | contribs)
Jump to navigation Jump to search

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)
  • Internet Explorer / Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5
  • Opera: Press Ctrl-F5.
// JavaScript to dynamically create and insert a table, only on a specific page
(function () {
  // Specify the page where the script should run
  const targetPage = "Target_Page_Name"; // Replace with your page's title (spaces replaced with underscores)

  // Get the current page name from MediaWiki
  const currentPage = mw.config.get("wgMeals");

  // Run the script only on the target page
  if (currentPage !== targetPage) return;

  // Check if the page content area exists
  const contentArea = document.getElementById("mw-content-text");
  if (!contentArea) return;

  // Create table element
  const table = document.createElement("table");
  table.className = "wikitable"; // MediaWiki styling class
  table.style.width = "50%";
  table.style.margin = "20px auto";

  // Add table header
  const headers = ["Name", "Age", "City"];
  const headerRow = document.createElement("tr");
  headers.forEach((header) => {
    const th = document.createElement("th");
    th.textContent = header;
    headerRow.appendChild(th);
  });
  table.appendChild(headerRow);

  // Add table rows with random data
  const data = [
    ["Alice", "25", "New York"],
    ["Bob", "30", "Los Angeles"],
    ["Charlie", "35", "Chicago"]
  ];

  data.forEach((row) => {
    const tableRow = document.createElement("tr");
    row.forEach((cell) => {
      const td = document.createElement("td");
      td.textContent = cell;
      tableRow.appendChild(td);
    });
    table.appendChild(tableRow);
  });

  // Insert the table into the page content area
  contentArea.prepend(table); // Add table at the top of the page content
})();