MediaWiki:Common.js: Difference between revisions
MediaWiki interface page
More actions
No edit summary |
No edit summary |
||
| Line 91: | Line 91: | ||
} | } | ||
})(); | })(); | ||
/* =========================== | /* =========================== | ||
| Line 101: | Line 102: | ||
if (!table) return; | if (!table) return; | ||
const | const container = document.getElementById("filterContainer"); | ||
if (!container) return; | |||
/* ---------- CREATE FILTER UI ---------- */ | |||
const wrapper = document.createElement("div"); | |||
wrapper.style.marginBottom = "15px"; | |||
const dungeonLabel = document.createElement("strong"); | |||
dungeonLabel.innerText = "Dungeon: "; | |||
wrapper.appendChild(dungeonLabel); | |||
const dungeonSelect = document.createElement("select"); | |||
dungeonSelect.style.marginRight = "20px"; | |||
const dungeons = [ | |||
"All", | |||
"Wolf's Den", | |||
"Wolf's Den II", | |||
"Wolf's Den III", | |||
"The Red Nest", | |||
"For The Eggs", | |||
"Scarlet Revenge", | |||
"Scarlet Revenge II", | |||
"Promised One", | |||
"Promised One II", | |||
"Promised One III", | |||
"Lost and Found", | |||
"The Hostage", | |||
"Cactus On Fire", | |||
"Deep Echoes", | |||
"Deep Echoes II", | |||
"Deep Echoes III" | |||
]; | |||
dungeons.forEach(name => { | |||
const option = document.createElement("option"); | |||
option.value = name; | |||
option.textContent = name; | |||
dungeonSelect.appendChild(option); | |||
}); | |||
wrapper.appendChild(dungeonSelect); | |||
function parseTime( | const playerLabel = document.createElement("strong"); | ||
if (! | playerLabel.innerText = "Player: "; | ||
const parts = | wrapper.appendChild(playerLabel); | ||
const playerInput = document.createElement("input"); | |||
playerInput.type = "text"; | |||
playerInput.placeholder = "Search player name..."; | |||
playerInput.style.padding = "4px"; | |||
wrapper.appendChild(playerInput); | |||
container.appendChild(wrapper); | |||
/* ---------- UTILITIES ---------- */ | |||
function parseTime(t) { | |||
if (!t || !t.includes(":")) return 999999; | |||
const parts = t.trim().split(":"); | |||
return parseInt(parts[0], 10) * 60 + parseInt(parts[1], 10); | |||
} | } | ||
function sortAndRank() { | |||
const rows = Array.from(table.querySelectorAll("tr")).slice(1); | |||
rows.sort((a, b) => { | |||
return | return parseTime(a.cells[4].innerText) - | ||
}); | parseTime(b.cells[4].innerText); | ||
}); | |||
rows.forEach(row => table.appendChild(row)); | |||
let visibleIndex = 0; | |||
rows.forEach(row => { | |||
if (row.style.display === "none") return; | |||
const rankCell = row.cells[0]; | |||
if (visibleIndex === 0) rankCell.innerHTML = "🥇 1"; | |||
else if (visibleIndex === 1) rankCell.innerHTML = "🥈 2"; | |||
else if (visibleIndex === 2) rankCell.innerHTML = "🥉 3"; | |||
else rankCell.innerText = visibleIndex + 1; | |||
visibleIndex++; | |||
}); | |||
} | |||
function filterTable() { | |||
const selectedDungeon = dungeonSelect.value; | |||
const playerSearch = playerInput.value.toLowerCase(); | |||
const rows = Array.from(table.querySelectorAll("tr")).slice(1); | |||
rows.forEach(row => { | |||
const dungeon = row.cells[1].innerText.trim(); | |||
const player = row.cells[2].innerText.toLowerCase(); | |||
const dungeonMatch = | |||
selectedDungeon === "All" || dungeon === selectedDungeon; | |||
const playerMatch = | |||
player.includes(playerSearch); | |||
row.style.display = | |||
(dungeonMatch && playerMatch) ? "" : "none"; | |||
}); | |||
sortAndRank(); | |||
} | |||
dungeonSelect.addEventListener("change", filterTable); | |||
playerInput.addEventListener("input", filterTable); | |||
sortAndRank(); | |||
}); | }); | ||