MediaWiki:Common.js: Difference between revisions
MediaWiki interface page
More actions
No edit summary |
No edit summary |
||
| Line 91: | Line 91: | ||
} | } | ||
})(); | })(); | ||
mw.hook('wikipage.content').add(function () { | mw.hook('wikipage.content').add(function () { | ||
const table = document.querySelector(".wikitable"); | |||
if (!table) return; | |||
const rows = Array.from(table.querySelectorAll("tr")); | |||
if (rows.length <= 1) return; | |||
const header = rows[0]; | |||
const dataRows = rows.slice(1); | |||
function parseTime(t) { | |||
if (!t || !t.includes(":")) return 999999; | |||
const parts = t.trim().split(":"); | |||
return parseInt(parts[0]) * 60 + parseInt(parts[1]); | |||
} | |||
dataRows.sort((a, b) => { | |||
const timeA = parseTime(a.cells[3].innerText); | |||
const timeB = parseTime(b.cells[3].innerText); | |||
return timeA - timeB; | |||
}); | |||
dataRows.forEach(row => table.appendChild(row)); | |||
dataRows.forEach((row, index) => { | |||
const rankCell = row.cells[0]; | |||
if (index === 0) rankCell.innerHTML = "🥇 1"; | |||
else if (index === 1) rankCell.innerHTML = "🥈 2"; | |||
else if (index === 2) rankCell.innerHTML = "🥉 3"; | |||
else rankCell.innerText = index + 1; | |||
}); | |||
}); | }); | ||