MediaWiki:Common.js: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
No edit summary |
||
Line 1: | Line 1: | ||
// JavaScript to dynamically create and insert a table, only on | // JavaScript to dynamically create and insert a table, only on the "Meals" page | ||
(function () { | (function () { | ||
// Specify the page | // Specify the page name (MediaWiki uses underscores for spaces in page titles) | ||
const targetPage = " | const targetPage = "Meals"; | ||
// Get the current page name from MediaWiki | // Get the current page name from MediaWiki's configuration | ||
const currentPage = mw.config.get(" | const currentPage = mw.config.get("wgPageName"); | ||
// Run the script only | // Run the script only if the current page matches the target page | ||
if (currentPage !== targetPage) return; | if (currentPage !== targetPage) return; | ||
// Check if the | // Check if the content area exists | ||
const contentArea = document.getElementById("mw-content-text"); | const contentArea = document.getElementById("mw-content-text"); | ||
if (!contentArea) return; | if (!contentArea) return; | ||
Line 16: | Line 16: | ||
// Create table element | // Create table element | ||
const table = document.createElement("table"); | const table = document.createElement("table"); | ||
table.className = "wikitable"; // MediaWiki styling | table.className = "wikitable"; // Apply MediaWiki's table styling | ||
table.style.width = "50%"; | table.style.width = "50%"; | ||
table.style.margin = "20px auto"; | table.style.margin = "20px auto"; | ||
// Add table header | // Add table header | ||
const headers = [" | const headers = ["Food", "Category", "Calories"]; | ||
const headerRow = document.createElement("tr"); | const headerRow = document.createElement("tr"); | ||
headers.forEach((header) => { | headers.forEach((header) => { | ||
const th = document.createElement("th"); | const th = document.createElement("th"); | ||
th.textContent = header; | th.textContent = header; | ||
headerRow | headerRow | ||
Revision as of 17:58, 15 December 2024
// 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