MediaWiki:Common.js

From Dragon Ball World Wiki
Revision as of 17:58, 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 the "Meals" page
(function () {
  // Specify the page name (MediaWiki uses underscores for spaces in page titles)
  const targetPage = "Meals";

  // Get the current page name from MediaWiki's configuration
  const currentPage = mw.config.get("wgPageName");

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

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

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

  // Add table header
  const headers = ["Food", "Category", "Calories"];
  const headerRow = document.createElement("tr");
  headers.forEach((header) => {
    const th = document.createElement("th");
    th.textContent = header;
    headerRow