MediaWiki:Common.js: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
No edit summary |
||
Line 22: | Line 22: | ||
toc.innerHTML = "<h2>Contents</h2>"; | toc.innerHTML = "<h2>Contents</h2>"; | ||
// Define the content list | // Define the content list with categories and IDs | ||
var contentList = [ | var contentList = [ | ||
{ name: "Common Monsters", id: "common-monsters" }, | { name: "Common Monsters", id: "common-monsters" }, | ||
Line 28: | Line 28: | ||
{ name: "Saga Monsters", id: "saga-monsters" }, | { name: "Saga Monsters", id: "saga-monsters" }, | ||
{ name: "Maze Monsters", id: "maze-monsters" }, | { name: "Maze Monsters", id: "maze-monsters" }, | ||
{ name: " | { name: "Dungeon Monsters", id: "dungeon-monsters" } | ||
]; | ]; | ||
Line 55: | Line 45: | ||
// Insert the table of contents at the top of the content area | // Insert the table of contents at the top of the content area | ||
contentArea.prepend(toc); | contentArea.prepend(toc); | ||
// Sample data for each category (10 monsters per category) | |||
var monsterData = { | |||
"common-monsters": [ | |||
"Goblin", "Slime", "Bat", "Wolf", "Zombie", "Rat", "Bandit", "Skeleton", "Orc", "Imp" | |||
], | |||
"mini-boss-monsters": [ | |||
"Giant Spider", "Troll", "Mummy", "Vampire", "Gorgon", "Minotaur", "Witch", "Golem", "Hydra", "Cerberus" | |||
], | |||
"saga-monsters": [ | |||
"Dragon", "Phoenix", "Griffin", "Unicorn", "Wyvern", "Basilisk", "Chimera", "Cyclops", "Kraken", "Roc" | |||
], | |||
"maze-monsters": [ | |||
"Minotaur", "Lich", "Necromancer", "Dark Knight", "Beholder", "Ghost", "Phantom", "Cursed Knight", "Ghoul", "Wraith" | |||
], | |||
"dungeon-monsters": [ | |||
"Mummy", "Phantom King", "Skeleton Warrior", "Dark Mage", "Bone Golem", "Witch", "Giant Spider", "Wraith", "Necromancer", "Cursed Beast" | |||
] | |||
}; | |||
// Create sections with ids corresponding to the table of contents | // Create sections with ids corresponding to the table of contents | ||
Line 63: | Line 72: | ||
// Add table header | // Add table header | ||
var headers = [" | var headers = ["Monster Name", "Category"]; | ||
var headerRow = document.createElement("tr"); | var headerRow = document.createElement("tr"); | ||
headers.forEach(function (header) { | headers.forEach(function (header) { | ||
Line 72: | Line 81: | ||
table.appendChild(headerRow); | table.appendChild(headerRow); | ||
// | // Function to create rows for each monster in a category | ||
function createCategoryRow(category, monsters) { | |||
var | var sectionRow = document.createElement("tr"); | ||
var categoryCell = document.createElement("td"); | |||
var anchor = document.createElement("a"); | |||
anchor.name = category; // Create anchor link for this category section | |||
categoryCell.appendChild(anchor); | |||
categoryCell.textContent = category.replace(/-/g, ' ').toUpperCase(); // Make category name readable | |||
sectionRow.appendChild(categoryCell); | |||
// Add | // Add monster names under each category | ||
var | var monstersCell = document.createElement("td"); | ||
monstersCell.innerHTML = monsters.join("<br>"); | |||
sectionRow.appendChild(monstersCell); | |||
return sectionRow; | |||
} | |||
table.appendChild( | // Add rows for each category and their monsters | ||
} | for (var category in monsterData) { | ||
var monsters = monsterData[category]; | |||
table.appendChild(createCategoryRow(category, monsters)); | |||
} | |||
// Insert the table after the table of contents | // Insert the table after the table of contents |
Revision as of 18:29, 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 with categories and 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: "Dungeon Monsters", id: "dungeon-monsters" } ]; // 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); // Sample data for each category (10 monsters per category) var monsterData = { "common-monsters": [ "Goblin", "Slime", "Bat", "Wolf", "Zombie", "Rat", "Bandit", "Skeleton", "Orc", "Imp" ], "mini-boss-monsters": [ "Giant Spider", "Troll", "Mummy", "Vampire", "Gorgon", "Minotaur", "Witch", "Golem", "Hydra", "Cerberus" ], "saga-monsters": [ "Dragon", "Phoenix", "Griffin", "Unicorn", "Wyvern", "Basilisk", "Chimera", "Cyclops", "Kraken", "Roc" ], "maze-monsters": [ "Minotaur", "Lich", "Necromancer", "Dark Knight", "Beholder", "Ghost", "Phantom", "Cursed Knight", "Ghoul", "Wraith" ], "dungeon-monsters": [ "Mummy", "Phantom King", "Skeleton Warrior", "Dark Mage", "Bone Golem", "Witch", "Giant Spider", "Wraith", "Necromancer", "Cursed Beast" ] }; // 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 = ["Monster Name", "Category"]; var headerRow = document.createElement("tr"); headers.forEach(function (header) { var th = document.createElement("th"); th.textContent = header; headerRow.appendChild(th); }); table.appendChild(headerRow); // Function to create rows for each monster in a category function createCategoryRow(category, monsters) { var sectionRow = document.createElement("tr"); var categoryCell = document.createElement("td"); var anchor = document.createElement("a"); anchor.name = category; // Create anchor link for this category section categoryCell.appendChild(anchor); categoryCell.textContent = category.replace(/-/g, ' ').toUpperCase(); // Make category name readable sectionRow.appendChild(categoryCell); // Add monster names under each category var monstersCell = document.createElement("td"); monstersCell.innerHTML = monsters.join("<br>"); sectionRow.appendChild(monstersCell); return sectionRow; } // Add rows for each category and their monsters for (var category in monsterData) { var monsters = monsterData[category]; table.appendChild(createCategoryRow(category, monsters)); } // Insert the table after the table of contents contentArea.appendChild(table); })(); });