MediaWiki:Common.js: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
No edit summary |
||
| (4 intermediate revisions by the same user not shown) | |||
| Line 1: | Line 1: | ||
mw.loader.using(["mediawiki.util"]).then(function () { | mw.loader.using(["mediawiki.util"]).then(function () { | ||
(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 | // Run the script only if the current page matches the target page | ||
if (currentPage !== targetPage) return; | if (currentPage !== targetPage) { | ||
return; | |||
} | |||
// Check if the content area exists | // Check if the content area exists | ||
var contentArea = document.getElementById("mw-content-text"); | |||
if (!contentArea) return; | if (!contentArea) { | ||
return; | |||
} | |||
// 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); | |||
// Define the categories and their sample monsters | |||
var monsterCategories = { | |||
"common-monsters": [ | |||
["Slime", "Level 1-10", "Low health, basic attack"], | |||
["Goblin", "Level 5-15", "Quick and nimble"], | |||
["Wolf", "Level 10-20", "Can be found in packs"], | |||
["Bandit", "Level 15-25", "Average strength, basic weapons"], | |||
["Rat", "Level 1-5", "Weak, commonly found in caves"], | |||
["Skeleton", "Level 20-30", "Basic undead with moderate strength"], | |||
["Orc", "Level 25-35", "Strong and slow, uses heavy weapons"], | |||
["Zombie", "Level 30-40", "Slow, but high health"], | |||
["Imp", "Level 10-20", "Magic user with fire attacks"], | |||
["Mummy", "Level 15-25", "Undead with poison attack"] | |||
], | |||
"mini-boss-monsters": [ | |||
["Vampire Lord", "Level 50-60", "High health, drains life"], | |||
["Dark Knight", "Level 45-55", "Powerful and armored"], | |||
["Demon Beast", "Level 60-70", "Summons minions, strong attack"], | |||
["Cyclops", "Level 50-60", "High damage, weak defense"], | |||
["Werewolf", "Level 55-65", "Fast and aggressive"], | |||
["Giant Spider", "Level 45-55", "Poisonous bite, high defense"], | |||
["Dragon Whelp", "Level 65-75", "Breathes fire, tough scales"], | |||
["Griffin", "Level 60-70", "Aerial monster with fast attacks"], | |||
["Minotaur", "Level 70-80", "Brutal strength, large axe"], | |||
["Basilisk", "Level 55-65", "Stone gaze and poison attack"] | |||
], | |||
// Add more categories as needed | |||
}; | |||
// Create a table to display the monsters | |||
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 = ["Monster", "Level Range", "Description"]; | |||
var headerRow = document.createElement("tr"); | |||
headers.forEach((header) | headers.forEach(function (header) { | ||
var th = document.createElement("th"); | |||
th.textContent = header; | th.textContent = header; | ||
headerRow.appendChild(th); | headerRow.appendChild(th); | ||
| Line 28: | Line 101: | ||
table.appendChild(headerRow); | table.appendChild(headerRow); | ||
// Add | // Add rows for each category with sample monsters | ||
Object.keys(monsterCategories).forEach(function (category) { | |||
// Add category header with link | |||
var sectionRow = document.createElement("tr"); | |||
var sectionCell = document.createElement("td"); | |||
sectionCell.colSpan = "3"; | |||
var anchor = document.createElement("a"); | |||
anchor.name = category; // Create anchor link for this section | |||
sectionCell.appendChild(anchor); | |||
sectionCell.textContent = category.replace("-", " ").toUpperCase(); | |||
sectionRow.appendChild(sectionCell); | |||
table.appendChild(sectionRow); | |||
// Add monsters for this category | |||
monsterCategories[category].forEach(function (monster) { | |||
var monsterRow = document.createElement("tr"); | |||
monster.forEach(function (data) { | |||
var cell = document.createElement("td"); | |||
cell.textContent = data; | |||
monsterRow.appendChild(cell); | |||
}); | |||
table.appendChild(monsterRow); | |||
}); | }); | ||
}); | }); | ||
// Insert the table | // Insert the table after the table of contents | ||
contentArea. | contentArea.appendChild(table); | ||
})(); | })(); | ||
}); | }); | ||
Latest 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 (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);
// Define the categories and their sample monsters
var monsterCategories = {
"common-monsters": [
["Slime", "Level 1-10", "Low health, basic attack"],
["Goblin", "Level 5-15", "Quick and nimble"],
["Wolf", "Level 10-20", "Can be found in packs"],
["Bandit", "Level 15-25", "Average strength, basic weapons"],
["Rat", "Level 1-5", "Weak, commonly found in caves"],
["Skeleton", "Level 20-30", "Basic undead with moderate strength"],
["Orc", "Level 25-35", "Strong and slow, uses heavy weapons"],
["Zombie", "Level 30-40", "Slow, but high health"],
["Imp", "Level 10-20", "Magic user with fire attacks"],
["Mummy", "Level 15-25", "Undead with poison attack"]
],
"mini-boss-monsters": [
["Vampire Lord", "Level 50-60", "High health, drains life"],
["Dark Knight", "Level 45-55", "Powerful and armored"],
["Demon Beast", "Level 60-70", "Summons minions, strong attack"],
["Cyclops", "Level 50-60", "High damage, weak defense"],
["Werewolf", "Level 55-65", "Fast and aggressive"],
["Giant Spider", "Level 45-55", "Poisonous bite, high defense"],
["Dragon Whelp", "Level 65-75", "Breathes fire, tough scales"],
["Griffin", "Level 60-70", "Aerial monster with fast attacks"],
["Minotaur", "Level 70-80", "Brutal strength, large axe"],
["Basilisk", "Level 55-65", "Stone gaze and poison attack"]
],
// Add more categories as needed
};
// Create a table to display the monsters
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", "Level Range", "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 category with sample monsters
Object.keys(monsterCategories).forEach(function (category) {
// Add category header with link
var sectionRow = document.createElement("tr");
var sectionCell = document.createElement("td");
sectionCell.colSpan = "3";
var anchor = document.createElement("a");
anchor.name = category; // Create anchor link for this section
sectionCell.appendChild(anchor);
sectionCell.textContent = category.replace("-", " ").toUpperCase();
sectionRow.appendChild(sectionCell);
table.appendChild(sectionRow);
// Add monsters for this category
monsterCategories[category].forEach(function (monster) {
var monsterRow = document.createElement("tr");
monster.forEach(function (data) {
var cell = document.createElement("td");
cell.textContent = data;
monsterRow.appendChild(cell);
});
table.appendChild(monsterRow);
});
});
// Insert the table after the table of contents
contentArea.appendChild(table);
})();
});