MediaWiki:Common.js: Difference between revisions
MediaWiki interface page
More actions
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. | 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( | function parseTime(timeString) { | ||
if (! | if (!timeString || !timeString.includes(":")) return 999999; | ||
const parts = | const parts = timeString.trim().split(":"); | ||
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]; | ||