MediaWiki:Common.js: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
No edit summary |
||
| Line 1: | Line 1: | ||
mw.loader.using(["mediawiki.util"]).then(function () { | mw.loader.using(["mediawiki.util"]).then(function () { | ||
(function () { | (function () { | ||
| Line 16: | Line 15: | ||
} | } | ||
// Create table | // 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"); | var table = document.createElement("table"); | ||
table.className = "wikitable"; // Apply MediaWiki's table styling | table.className = "wikitable"; // Apply MediaWiki's table styling | ||
table.style.width = " | table.style.width = "100%"; | ||
table.style.margin = "20px auto"; | table.style.margin = "20px auto"; | ||
// Add table header | // Add table header | ||
var headers = [" | var headers = ["Section", "Description"]; | ||
var headerRow = document.createElement("tr"); | var headerRow = document.createElement("tr"); | ||
headers.forEach(function (header) { | headers.forEach(function (header) { | ||
| Line 32: | Line 72: | ||
table.appendChild(headerRow); | table.appendChild(headerRow); | ||
// Add | // Add rows for each section with sample data | ||
var | 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); | table.appendChild(tableRow); | ||
}); | }); | ||
// Insert the table | // Insert the table after the table of contents | ||
contentArea. | contentArea.appendChild(table); | ||
})(); | })(); | ||
}); | }); | ||
Revision as of 18:26, 15 December 2024
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);
})();
});