MediaWiki:Common.js: Difference between revisions
MediaWiki interface page
More actions
No edit summary |
No edit summary |
||
| Line 1: | Line 1: | ||
/* Any JavaScript here will be loaded for all users on every page load. */// Load DataTables library | /* Any JavaScript here will be loaded for all users on every page load. */// Load DataTables library | ||
/* Any JavaScript here will be loaded for all users on every page load. */ | |||
mw.hook('wikipage.content').add(function ($content) { | mw.hook('wikipage.content').add(function ($content) { | ||
| Line 7: | Line 8: | ||
}); | }); | ||
/* =========================== | |||
Dungeon Speedrun Leaderboard | |||
=========================== */ | |||
mw.hook('wikipage.content').add(function () { | |||
function parseTime(t) { | |||
if (!t || !t.includes(":")) return 999999; | |||
const parts = t.trim().split(":"); | |||
return parseInt(parts[0], 10) * 60 + parseInt(parts[1], 10); | |||
} | } | ||
/* =========================== | |||
SOLO TABLE | |||
=========================== */ | |||
const table = document.getElementById("leaderboardTable"); | |||
if (table) { | |||
const container = document.getElementById("filterContainer"); | |||
if (container) { | if (container) { | ||
| Line 118: | Line 46: | ||
const dungeons = [ | const dungeons = [ | ||
"All", | "All", | ||
"Wolf's Den", "Wolf's Den II", "Wolf's Den III", | "Wolf's Den","Wolf's Den II","Wolf's Den III", | ||
"The Red Nest", "For The Eggs", | "The Red Nest","For The Eggs", | ||
"Scarlet Revenge", "Scarlet Revenge II", | "Scarlet Revenge","Scarlet Revenge II", | ||
"Promised One", "Promised One II", "Promised One III", | "Promised One","Promised One II","Promised One III", | ||
"Lost and Found", "The Hostage", "Cactus On Fire", | "Lost and Found","The Hostage","Cactus On Fire", | ||
"Deep Echoes", "Deep Echoes II", "Deep Echoes III", "King's Hoard" , "King's Hoard II", | "Deep Echoes","Deep Echoes II","Deep Echoes III", | ||
"Hall of Daggers" | "King's Hoard","King's Hoard II", | ||
"Hall of Daggers" | |||
]; | ]; | ||
| Line 148: | Line 77: | ||
container.appendChild(wrapper); | container.appendChild(wrapper); | ||
function sortAndRank() { | function sortAndRank() { | ||
const rows = Array.from(table.querySelectorAll("tr")).slice(1); | const rows = Array.from(table.querySelectorAll("tr")).slice(1); | ||
rows.sort((a, b) => { | |||
rows.sort((a,b) => { | |||
const dungeonA = a.cells[1].innerText.trim(); | const dungeonA = a.cells[1].innerText.trim(); | ||
const dungeonB = b.cells[1].innerText.trim(); | const dungeonB = b.cells[1].innerText.trim(); | ||
if (dungeonA < dungeonB) return -1; | if (dungeonA < dungeonB) return -1; | ||
if (dungeonA > dungeonB) return 1; | if (dungeonA > dungeonB) return 1; | ||
return parseTime(a.cells[4].innerText) - parseTime(b.cells[4].innerText); | return parseTime(a.cells[4].innerText) - parseTime(b.cells[4].innerText); | ||
}); | }); | ||
rows.forEach(row => table.appendChild(row)); | rows.forEach(row => table.appendChild(row)); | ||
let currentDungeon = ""; | let currentDungeon = ""; | ||
let dungeonRank = 0; | let dungeonRank = 0; | ||
rows.forEach(row => { | rows.forEach(row => { | ||
const dungeon = row.cells[1].innerText.trim(); | const dungeon = row.cells[1].innerText.trim(); | ||
const rankCell = row.cells[0]; | const rankCell = row.cells[0]; | ||
if (dungeon !== currentDungeon) { currentDungeon = dungeon; dungeonRank = 1; | |||
else { dungeonRank++; } | if (dungeon !== currentDungeon) { | ||
currentDungeon = dungeon; | |||
dungeonRank = 1; | |||
} else { | |||
dungeonRank++; | |||
} | |||
if (dungeonRank === 1) rankCell.innerHTML = "🥇 1"; | if (dungeonRank === 1) rankCell.innerHTML = "🥇 1"; | ||
else if (dungeonRank === 2) rankCell.innerHTML = "🥈 2"; | else if (dungeonRank === 2) rankCell.innerHTML = "🥈 2"; | ||
else if (dungeonRank === 3) rankCell.innerHTML = "🥉 3"; | else if (dungeonRank === 3) rankCell.innerHTML = "🥉 3"; | ||
else rankCell.innerText = dungeonRank; | else rankCell.innerText = dungeonRank; | ||
}); | }); | ||
} | } | ||
function filterTable() { | function filterTable() { | ||
const selectedDungeon = dungeonSelect.value; | const selectedDungeon = dungeonSelect.value; | ||
const playerSearch = playerInput.value.toLowerCase(); | const playerSearch = playerInput.value.toLowerCase(); | ||
const rows = Array.from(table.querySelectorAll("tr")).slice(1); | const rows = Array.from(table.querySelectorAll("tr")).slice(1); | ||
rows.forEach(row => { | rows.forEach(row => { | ||
const dungeon = row.cells[1].innerText.trim(); | const dungeon = row.cells[1].innerText.trim(); | ||
const player = row.cells[2].innerText.toLowerCase(); | const player = row.cells[2].innerText.toLowerCase(); | ||
row.style.display = | row.style.display = | ||
(selectedDungeon === "All" || dungeon === selectedDungeon) && | (selectedDungeon === "All" || dungeon === selectedDungeon) && | ||
player.includes(playerSearch) ? "" : "none"; | player.includes(playerSearch) | ||
? "" | |||
: "none"; | |||
}); | }); | ||
} | } | ||
dungeonSelect.addEventListener("change", filterTable); | dungeonSelect.addEventListener("change", filterTable); | ||
playerInput.addEventListener("input", filterTable); | playerInput.addEventListener("input", filterTable); | ||
sortAndRank(); | sortAndRank(); | ||
} | } | ||
} | } | ||
/ | |||
/* =========================== | |||
PARTY TABLE | |||
=========================== */ | |||
const partyTable = document.getElementById("partyLeaderboardTable"); | const partyTable = document.getElementById("partyLeaderboardTable"); | ||
if (partyTable) { | if (partyTable) { | ||
const partyContainer = document.getElementById("partyFilterContainer"); | const partyContainer = document.getElementById("partyFilterContainer"); | ||
if (partyContainer) { | if (partyContainer) { | ||
| Line 218: | Line 175: | ||
const dungeons = [ | const dungeons = [ | ||
"All", | "All", | ||
"Wolf's Den", "Wolf's Den II", "Wolf's Den III", | "Wolf's Den","Wolf's Den II","Wolf's Den III", | ||
"The Red Nest", "For The Eggs", | "The Red Nest","For The Eggs", | ||
"Scarlet Revenge", "Scarlet Revenge II", | "Scarlet Revenge","Scarlet Revenge II", | ||
"Promised One", "Promised One II", "Promised One III", | "Promised One","Promised One II","Promised One III", | ||
"Lost and Found", "The Hostage", "Cactus On Fire", | "Lost and Found","The Hostage","Cactus On Fire", | ||
"Deep Echoes", "Deep Echoes II", "Deep Echoes III", "King's Hoard", "King's Hoard II", | "Deep Echoes","Deep Echoes II","Deep Echoes III", | ||
"Hall of Daggers" | "King's Hoard","King's Hoard II", | ||
"Hall of Daggers" | |||
]; | ]; | ||
| Line 248: | Line 206: | ||
partyContainer.appendChild(wrapper); | partyContainer.appendChild(wrapper); | ||
function sortAndRankParty() { | function sortAndRankParty() { | ||
const rows = Array.from(partyTable.querySelectorAll("tr")).slice(1); | const rows = Array.from(partyTable.querySelectorAll("tr")).slice(1); | ||
rows.sort((a, b) => { | |||
rows.sort((a,b) => { | |||
const dungeonA = a.cells[1].innerText.trim(); | const dungeonA = a.cells[1].innerText.trim(); | ||
const dungeonB = b.cells[1].innerText.trim(); | const dungeonB = b.cells[1].innerText.trim(); | ||
if (dungeonA < dungeonB) return -1; | if (dungeonA < dungeonB) return -1; | ||
if (dungeonA > dungeonB) return 1; | if (dungeonA > dungeonB) return 1; | ||
return parseTime(a.cells[5].innerText) - parseTime(b.cells[5].innerText); | return parseTime(a.cells[5].innerText) - parseTime(b.cells[5].innerText); | ||
}); | }); | ||
rows.forEach(row => partyTable.appendChild(row)); | rows.forEach(row => partyTable.appendChild(row)); | ||
let currentDungeon = ""; | let currentDungeon = ""; | ||
let dungeonRank = 0; | let dungeonRank = 0; | ||
rows.forEach(row => { | rows.forEach(row => { | ||
const dungeon = row.cells[1].innerText.trim(); | const dungeon = row.cells[1].innerText.trim(); | ||
const rankCell = row.cells[0]; | const rankCell = row.cells[0]; | ||
if (dungeon !== currentDungeon) { currentDungeon = dungeon; dungeonRank = 1; | |||
else { dungeonRank++; } | if (dungeon !== currentDungeon) { | ||
currentDungeon = dungeon; | |||
dungeonRank = 1; | |||
} else { | |||
dungeonRank++; | |||
} | |||
if (dungeonRank === 1) rankCell.innerHTML = "🥇 1"; | if (dungeonRank === 1) rankCell.innerHTML = "🥇 1"; | ||
else if (dungeonRank === 2) rankCell.innerHTML = "🥈 2"; | else if (dungeonRank === 2) rankCell.innerHTML = "🥈 2"; | ||
else if (dungeonRank === 3) rankCell.innerHTML = "🥉 3"; | else if (dungeonRank === 3) rankCell.innerHTML = "🥉 3"; | ||
else rankCell.innerText = dungeonRank; | else rankCell.innerText = dungeonRank; | ||
}); | }); | ||
} | } | ||
function filterPartyTable() { | function filterPartyTable() { | ||
const selectedDungeon = dungeonSelect.value; | const selectedDungeon = dungeonSelect.value; | ||
const playerSearch = playerInput.value.toLowerCase(); | const playerSearch = playerInput.value.toLowerCase(); | ||
const rows = Array.from(partyTable.querySelectorAll("tr")).slice(1); | const rows = Array.from(partyTable.querySelectorAll("tr")).slice(1); | ||
rows.forEach(row => { | rows.forEach(row => { | ||
const dungeon = row.cells[1].innerText.trim(); | const dungeon = row.cells[1].innerText.trim(); | ||
const player = row.cells[3].innerText.toLowerCase(); | const player = row.cells[3].innerText.toLowerCase(); | ||
row.style.display = | row.style.display = | ||
(selectedDungeon === "All" || dungeon === selectedDungeon) && | (selectedDungeon === "All" || dungeon === selectedDungeon) && | ||
player.includes(playerSearch) ? "" : "none"; | player.includes(playerSearch) | ||
? "" | |||
: "none"; | |||
}); | }); | ||
} | } | ||
dungeonSelect.addEventListener("change", filterPartyTable); | dungeonSelect.addEventListener("change", filterPartyTable); | ||
playerInput.addEventListener("input", filterPartyTable); | playerInput.addEventListener("input", filterPartyTable); | ||
sortAndRankParty(); | sortAndRankParty(); | ||
} | } | ||
} | } | ||
}); | }); | ||