MediaWiki:Common.js
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.
mw.loader.using(["mediawiki.util"]).then(function () {
(function () {
var targetPage = "Meals"; // Target page name
var 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
var contentArea = document.getElementById("mw-content-text");
if (!contentArea) {
return;
}
// Create a table of contents
var toc = document.createElement("div");
toc.className = "toc";
toc.style.marginBottom = "20px";
toc.style.fontWeight = "bold";
toc.innerHTML = "<h2>Contents</h2>";
// Define the content list (title and section ids)
var contentList = [
{ name: "Common Monsters", id: "common-monsters" },
{ name: "Mini Boss Monsters", id: "mini-boss-monsters" },
{ name: "Saga Monsters", id: "saga-monsters" },
{ name: "Maze Monsters", id: "maze-monsters" },
{ name: "Ancient Temple [100 - 169]", id: "ancient-temple" },
{ name: "Hellish Vanguard [100 - 169]", id: "hellish-vanguard" },
{ name: "Lost Graveyard [170 - 239]", id: "lost-graveyard" },
{ name: "Heaven Hills [170 - 239]", id: "heaven-hills" },
{ name: "Frozen Lair [240 - 299]", id: "frozen-lair" },
{ name: "Saiyan Bandits Hideout Siege [240 - 299]", id: "saiyan-bandits-hideout" },
{ name: "Curse of Pharaoh (20-39)", id: "curse-of-pharaoh" },
{ name: "Mafia Dungeon (40-59)", id: "mafia-dungeon" },
{ name: "Army Secret (60-99)", id: "army-secret" },
{ name: "Jungle Adventure (100-129)", id: "jungle-adventure" },
{ name: "Namek Dungeon (130-169)", id: "namek-dungeon" }
];
// Create a list of links for the table of contents
var tocList = document.createElement("ul");
contentList.forEach(function (content) {
var listItem = document.createElement("li");
var link = document.createElement("a");
link.href = "#" + content.id;
link.textContent = content.name;
listItem.appendChild(link);
tocList.appendChild(listItem);
});
toc.appendChild(tocList);
// Insert the table of contents at the top of the content area
contentArea.prepend(toc);
// Create sections with ids corresponding to the table of contents
var table = document.createElement("table");
table.className = "wikitable"; // Apply MediaWiki's table styling
table.style.width = "100%";
table.style.margin = "20px auto";
// Add table header
var headers = ["Section", "Description"];
var headerRow = document.createElement("tr");
headers.forEach(function (header) {
var th = document.createElement("th");
th.textContent = header;
headerRow.appendChild(th);
});
table.appendChild(headerRow);
// Add rows for each section with sample data
contentList.forEach(function (content) {
var tableRow = document.createElement("tr");
// Add section name with anchor link
var sectionCell = document.createElement("td");
var anchor = document.createElement("a");
anchor.name = content.id; // Create anchor link for this section
sectionCell.appendChild(anchor);
sectionCell.textContent = content.name;
tableRow.appendChild(sectionCell);
// Add sample description for each section
var descriptionCell = document.createElement("td");
descriptionCell.textContent = "Sample description for " + content.name;
tableRow.appendChild(descriptionCell);
table.appendChild(tableRow);
});
// Insert the table after the table of contents
contentArea.appendChild(table);
})();
});