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 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); })(); });