MediaWiki:Common.js

From Dragon Ball World Wiki
Jump to navigation Jump to search

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