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 (title and section ids)
     // 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: "Ancient Temple [100 - 169]", id: "ancient-temple" },
       { name: "Dungeon Monsters", id: "dungeon-monsters" }
      { 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 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 = ["Section", "Description"];
     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);


     // Add rows for each section with sample data
     // Function to create rows for each monster in a category
     contentList.forEach(function (content) {
     function createCategoryRow(category, monsters) {
       var tableRow = document.createElement("tr");
       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 section name with anchor link
       // Add monster names under each category
       var sectionCell = document.createElement("td");
       var monstersCell = document.createElement("td");
       var anchor = document.createElement("a");
       monstersCell.innerHTML = monsters.join("<br>");
       anchor.name = content.id;  // Create anchor link for this section
       sectionRow.appendChild(monstersCell);
      sectionCell.appendChild(anchor);
      sectionCell.textContent = content.name;
      tableRow.appendChild(sectionCell);


       // Add sample description for each section
       return sectionRow;
      var descriptionCell = document.createElement("td");
    }
      descriptionCell.textContent = "Sample description for " + content.name;
      tableRow.appendChild(descriptionCell);


       table.appendChild(tableRow);
    // 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);
  })();
});