Toggle menu
Toggle preferences menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

MediaWiki:Common.js: Difference between revisions

MediaWiki interface page
No edit summary
No edit summary
Line 91: Line 91:
   }
   }
})();
})();


/* ===========================
/* ===========================
   Dungeon Leaderboard Script
   Dungeon Speedrun Leaderboard
  Per-Dungeon Ranking + Filters
   =========================== */
   =========================== */


mw.hook('wikipage.content').add(function () {
mw.hook('wikipage.content').add(function () {


   // ONLY run on Dungeon Leaderboard page
   // Run only if table exists
  if (mw.config.get('wgPageName') !== "Dungeon_Leaderboard") return;
 
   const table = document.getElementById("leaderboardTable");
   const table = document.getElementById("leaderboardTable");
   if (!table) return;
   if (!table) return;
Line 112: Line 112:
   wrapper.style.marginBottom = "15px";
   wrapper.style.marginBottom = "15px";


  // Dungeon dropdown
   const dungeonLabel = document.createElement("strong");
   const dungeonLabel = document.createElement("strong");
   dungeonLabel.innerText = "Dungeon: ";
   dungeonLabel.innerText = "Dungeon: ";
Line 148: Line 149:
   wrapper.appendChild(dungeonSelect);
   wrapper.appendChild(dungeonSelect);


  // Player search
   const playerLabel = document.createElement("strong");
   const playerLabel = document.createElement("strong");
   playerLabel.innerText = "Player: ";
   playerLabel.innerText = "Player: ";
Line 171: Line 173:
     const rows = Array.from(table.querySelectorAll("tr")).slice(1);
     const rows = Array.from(table.querySelectorAll("tr")).slice(1);


     rows.sort((a, b) =>
    // Sort by Dungeon first, then Time
       parseTime(a.cells[4].innerText) -
     rows.sort((a, b) => {
      parseTime(b.cells[4].innerText)
      const dungeonA = a.cells[1].innerText.trim();
     );
      const dungeonB = b.cells[1].innerText.trim();
 
      if (dungeonA < dungeonB) return -1;
      if (dungeonA > dungeonB) return 1;
 
       return parseTime(a.cells[4].innerText) -
            parseTime(b.cells[4].innerText);
     });


     rows.forEach(row => table.appendChild(row));
     rows.forEach(row => table.appendChild(row));


     let visibleIndex = 0;
     let currentDungeon = "";
    let dungeonRank = 0;


     rows.forEach(row => {
     rows.forEach(row => {
       if (row.style.display === "none") return;
       if (row.style.display === "none") return;


      const dungeon = row.cells[1].innerText.trim();
       const rankCell = row.cells[0];
       const rankCell = row.cells[0];


       if (visibleIndex === 0) rankCell.innerHTML = "🥇 1";
       if (dungeon !== currentDungeon) {
      else if (visibleIndex === 1) rankCell.innerHTML = "🥈 2";
        currentDungeon = dungeon;
       else if (visibleIndex === 2) rankCell.innerHTML = "🥉 3";
        dungeonRank = 1;
       else rankCell.innerText = visibleIndex + 1;
       } else {
        dungeonRank++;
       }


       visibleIndex++;
       if (dungeonRank === 1) rankCell.innerHTML = "🥇 1";
      else if (dungeonRank === 2) rankCell.innerHTML = "🥈 2";
      else if (dungeonRank === 3) rankCell.innerHTML = "🥉 3";
      else rankCell.innerText = dungeonRank;
     });
     });
   }
   }