MediaWiki:Common.js

From Dragon Ball World Wiki
Revision as of 17:53, 15 December 2024 by Titan099 (talk | contribs) (Created page with "→‎Any JavaScript here will be loaded for all users on every page load.: // JavaScript to dynamically create and insert a table into a MediaWiki page (function () { // 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%"; tabl...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
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.
/* Any JavaScript here will be loaded for all users on every page load. */
// JavaScript to dynamically create and insert a table into a MediaWiki page
(function () {
  // 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
})();