forked from X-DIABLO-X/LEADERBOARD
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rank.html
96 lines (85 loc) · 3.37 KB
/
rank.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Scaler Leaderboard</title>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<div class="container">
<h1>Scaler Leaderboard</h1>
<div class="toggle-container">
<button class="dark-mode-toggle" aria-label="Toggle Dark Mode" onclick="toggleDarkMode()">Toggle Dark Mode</button>
<div class="search-container">
<input type="text" id="searchInput" placeholder="Search by name..." aria-label="Search by name" onkeyup="filterLeaderboard()">
</div>
</div>
<table>
<thead>
<tr>
<th onclick="sortTable(0)">Rank</th>
<th onclick="sortTable(1)">Name</th>
<th onclick="sortTable(2)">CodeChef</th>
<th onclick="sortTable(3)">Codeforces</th>
<th onclick="sortTable(4)">AtCoder</th>
<th onclick="sortTable(5)">LeetCode</th>
<th>Total</th>
</tr>
</thead>
<tbody id="leaderboardBody">
<!-- Sample data; replace with dynamic data -->
<tr>
<td>1</td>
<td>John Doe</td>
<td>1500</td>
<td>1600</td>
<td>1700</td>
<td>1800</td>
<td>8200</td>
</tr>
<tr>
<td>2</td>
<td>Jane Smith</td>
<td>1600</td>
<td>1700</td>
<td>1800</td>
<td>1900</td>
<td>9000</td>
</tr>
<!-- Add more rows as needed -->
</tbody>
</table>
</div>
<script src="rank.js"></script>
<script>
// Toggle dark mode
function toggleDarkMode() {
document.body.classList.toggle("dark-mode");
}
// Filter leaderboard based on search input
function filterLeaderboard() {
const input = document.getElementById("searchInput").value.toLowerCase();
const rows = document.querySelectorAll("#leaderboardBody tr");
rows.forEach(row => {
const nameCell = row.querySelector("td:nth-child(2)");
row.style.display = nameCell.textContent.toLowerCase().includes(input) ? "" : "none";
});
}
// Sort table based on clicked column
function sortTable(columnIndex) {
const table = document.querySelector("table");
const rows = Array.from(table.rows).slice(1);
const isAscending = table.querySelector(`th:nth-child(${columnIndex + 1})`).classList.toggle("asc");
rows.sort((a, b) => {
const aText = a.cells[columnIndex].textContent;
const bText = b.cells[columnIndex].textContent;
return isAscending
? aText.localeCompare(bText, undefined, { numeric: true })
: bText.localeCompare(aText, undefined, { numeric: true });
});
rows.forEach(row => table.appendChild(row)); // Append rows in the new order
}
</script>
</body>
</html>