MediaWiki:Common.js: Difference between revisions

From Dragon Ball World Wiki
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 with categories and IDs
     // Define the content list (title and section 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: "Dungeon Monsters", id: "dungeon-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" }
     ];
     ];


Line 46: Line 56:
     contentArea.prepend(toc);
     contentArea.prepend(toc);


     // Sample data for each category (10 monsters per category)
     // Define the categories and their sample monsters
     var monsterData = {
     var monsterCategories = {
       "common-monsters": [
       "common-monsters": [
         "Goblin", "Slime", "Bat", "Wolf", "Zombie", "Rat", "Bandit", "Skeleton", "Orc", "Imp"
         ["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": [
       "mini-boss-monsters": [
         "Giant Spider", "Troll", "Mummy", "Vampire", "Gorgon", "Minotaur", "Witch", "Golem", "Hydra", "Cerberus"
         ["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"]
       ],
       ],
       "saga-monsters": [
       // Add more categories as needed
        "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 a table to display the monsters
     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
Line 72: Line 92:


     // Add table header
     // Add table header
     var headers = ["Monster Name", "Category"];
     var headers = ["Monster", "Level Range", "Description"];
     var headerRow = document.createElement("tr");
     var headerRow = document.createElement("tr");
     headers.forEach(function (header) {
     headers.forEach(function (header) {
Line 81: Line 101:
     table.appendChild(headerRow);
     table.appendChild(headerRow);


     // Function to create rows for each monster in a category
     // Add rows for each category with sample monsters
     function createCategoryRow(category, monsters) {
     Object.keys(monsterCategories).forEach(function (category) {
      // Add category header with link
       var sectionRow = document.createElement("tr");
       var sectionRow = document.createElement("tr");
       var categoryCell = document.createElement("td");
       var sectionCell = document.createElement("td");
      sectionCell.colSpan = "3";
       var anchor = document.createElement("a");
       var anchor = document.createElement("a");
       anchor.name = category;  // Create anchor link for this category section
       anchor.name = category;  // Create anchor link for this section
       categoryCell.appendChild(anchor);
       sectionCell.appendChild(anchor);
       categoryCell.textContent = category.replace(/-/g, ' ').toUpperCase(); // Make category name readable
       sectionCell.textContent = category.replace("-", " ").toUpperCase();
       sectionRow.appendChild(categoryCell);
       sectionRow.appendChild(sectionCell);
      table.appendChild(sectionRow);


       // Add monster names under each category
       // Add monsters for this category
       var monstersCell = document.createElement("td");
       monsterCategories[category].forEach(function (monster) {
      monstersCell.innerHTML = monsters.join("<br>");
        var monsterRow = document.createElement("tr");
      sectionRow.appendChild(monstersCell);
        monster.forEach(function (data) {
 
          var cell = document.createElement("td");
      return sectionRow;
          cell.textContent = data;
    }
          monsterRow.appendChild(cell);
 
        });
    // Add rows for each category and their monsters
        table.appendChild(monsterRow);
    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

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