MediaWiki:Common.js: Difference between revisions
MediaWiki interface page
More actions
No edit summary |
No edit summary |
||
| Line 91: | Line 91: | ||
} | } | ||
})(); | })(); | ||
/* =========================== | /* =========================== | ||
Dungeon Leaderboard | Dungeon Speedrun Leaderboard | ||
Per-Dungeon Ranking + Filters | |||
=========================== */ | =========================== */ | ||
mw.hook('wikipage.content').add(function () { | mw.hook('wikipage.content').add(function () { | ||
// | // Run only if table exists | ||
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) => { | ||
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 | 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 ( | if (dungeon !== currentDungeon) { | ||
currentDungeon = dungeon; | |||
else | dungeonRank = 1; | ||
} else { | |||
dungeonRank++; | |||
} | |||
if (dungeonRank === 1) rankCell.innerHTML = "🥇 1"; | |||
else if (dungeonRank === 2) rankCell.innerHTML = "🥈 2"; | |||
else if (dungeonRank === 3) rankCell.innerHTML = "🥉 3"; | |||
else rankCell.innerText = dungeonRank; | |||
}); | }); | ||
} | } | ||