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


/* ===========================
  Dungeon Leaderboard Script
  =========================== */


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


   const table = document.querySelector(".wikitable");
   const table = document.getElementById("leaderboardTable");
   if (!table) return;
   if (!table) return;


   const rows = Array.from(table.querySelectorAll("tr"));
   const rows = Array.from(table.querySelectorAll("tr"));


  // Must have header + at least 1 row
   if (rows.length <= 1) return;
   if (rows.length <= 1) return;


Line 105: Line 109:
   const dataRows = rows.slice(1);
   const dataRows = rows.slice(1);


   function parseTime(t) {
   function parseTime(timeString) {
     if (!t || !t.includes(":")) return 999999;
     if (!timeString || !timeString.includes(":")) return 999999;
     const parts = t.trim().split(":");
     const parts = timeString.trim().split(":");
     return parseInt(parts[0]) * 60 + parseInt(parts[1]);
     const minutes = parseInt(parts[0], 10);
    const seconds = parseInt(parts[1], 10);
    return (minutes * 60) + seconds;
   }
   }


  // Sort rows by Time column (column index 3)
   dataRows.sort((a, b) => {
   dataRows.sort((a, b) => {
     const timeA = parseTime(a.cells[3].innerText);
     const timeA = parseTime(a.cells[3].innerText);
Line 117: Line 124:
   });
   });


  // Re-append sorted rows
   dataRows.forEach(row => table.appendChild(row));
   dataRows.forEach(row => table.appendChild(row));


  // Apply ranking
   dataRows.forEach((row, index) => {
   dataRows.forEach((row, index) => {
     const rankCell = row.cells[0];
     const rankCell = row.cells[0];