Dungeon Leadboard: Difference between revisions
From Treeverse
More actions
No edit summary Tag: visualeditor-switched |
No edit summary |
||
| Line 1: | Line 1: | ||
= Dungeon | /* =========================== | ||
Dungeon Leaderboard Script | |||
=========================== */ | |||
mw.hook('wikipage.content').add(function ($content) { | |||
const table = document.getElementById("leaderboardTable"); | |||
if (!table) return; | |||
const dungeonFilter = document.getElementById("filterDungeon"); | |||
const typeFilter = document.getElementById("filterType"); | |||
const addBtn = document.getElementById("addRunBtn"); | |||
if (!addBtn) return; | |||
function parseTime(t) { | |||
if (!t || !t.includes(":")) return 999999; | |||
const parts = t.split(":"); | |||
return parseInt(parts[0]) * 60 + parseInt(parts[1]); | |||
} | |||
function sortAndRank() { | |||
const rows = Array.from(table.rows).slice(1); | |||
rows.sort((a, b) => { | |||
return parseTime(a.cells[6].innerText) - parseTime(b.cells[6].innerText); | |||
}); | |||
rows.forEach(row => table.appendChild(row)); | |||
rows.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; | |||
}); | |||
} | |||
function filterTable() { | |||
const selectedDungeon = dungeonFilter.value; | |||
const selectedType = typeFilter.value; | |||
Array.from(table.rows).slice(1).forEach(row => { | |||
const dungeon = row.cells[1].innerText.trim(); | |||
const type = row.cells[2].innerText.trim(); | |||
const show = | |||
(selectedDungeon === "All" || dungeon === selectedDungeon) && | |||
(selectedType === "All" || type === selectedType); | |||
row.style.display = show ? "" : "none"; | |||
}); | |||
} | |||
if (dungeonFilter) dungeonFilter.addEventListener("change", filterTable); | |||
if (typeFilter) typeFilter.addEventListener("change", filterTable); | |||
addBtn.addEventListener("click", function () { | |||
alert("Button working — modal should appear next."); | |||
}); | |||
sortAndRank(); | |||
}); | |||
Revision as of 23:53, 28 February 2026
/* ===========================
Dungeon Leaderboard Script =========================== */
mw.hook('wikipage.content').add(function ($content) {
const table = document.getElementById("leaderboardTable");
if (!table) return;
const dungeonFilter = document.getElementById("filterDungeon");
const typeFilter = document.getElementById("filterType");
const addBtn = document.getElementById("addRunBtn");
if (!addBtn) return;
function parseTime(t) {
if (!t || !t.includes(":")) return 999999;
const parts = t.split(":");
return parseInt(parts[0]) * 60 + parseInt(parts[1]);
}
function sortAndRank() {
const rows = Array.from(table.rows).slice(1);
rows.sort((a, b) => {
return parseTime(a.cells[6].innerText) - parseTime(b.cells[6].innerText);
});
rows.forEach(row => table.appendChild(row));
rows.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;
});
}
function filterTable() {
const selectedDungeon = dungeonFilter.value;
const selectedType = typeFilter.value;
Array.from(table.rows).slice(1).forEach(row => {
const dungeon = row.cells[1].innerText.trim();
const type = row.cells[2].innerText.trim();
const show =
(selectedDungeon === "All" || dungeon === selectedDungeon) &&
(selectedType === "All" || type === selectedType);
row.style.display = show ? "" : "none";
});
}
if (dungeonFilter) dungeonFilter.addEventListener("change", filterTable);
if (typeFilter) typeFilter.addEventListener("change", filterTable);
addBtn.addEventListener("click", function () {
alert("Button working — modal should appear next.");
});
sortAndRank();
});