Repository navigation
Expand file tree
/
Copy pathsta.html
More file actions
105 lines (95 loc) · 2.94 KB
/
Copy pathsta.html
File metadata and controls
105 lines (95 loc) · 2.94 KB
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
96
97
98
99
100
101
102
103
104
105
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<link href="https://huntingstats378.github.io/HuntingStats378/main/assets/ess/odometer.css" rel="stylesheet">
<script src="https://huntingstats378.github.io/HuntingStats378/main/assets/ess/odometer.js"></script>
<title>Live XP Counter</title>
<style>
body {
background-color: #111;
color: #fff;
font-family: Arial, sans-serif;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
height: 100vh;
text-align: center;
}
h1 {
color: #E65724;
font-size: 3rem;
}
#xpCounter {
font-size: 100px;
margin-top: 20px;
}
</style>
</head>
<body>
<h1 id="name">Live XP Counter</h1>
<div class="odometer" id="xpCounter">Loading...</div>
<script>
const BASE_URL = "https://huntingstats378.onrender.com/corsproxy?url=https://api.lurkr.gg/v2/levels/1150096734576451614";
let currentPage = 1;
function getAvatarURL(user) {
if (!user.user.avatar || !user.userId) return "./default.png";
const isGif = user.user.avatar.startsWith("a_");
const extension = isGif ? "gif" : "png";
return `https://cdn.discordapp.com/avatars/${user.userId}/${user.user.avatar}.${extension}`;
}
function getUserIdFromURL() {
const params = new URLSearchParams(window.location.search);
return params.get("id");
}
async function fetchUserFromPage(userId, page) {
const url = `${BASE_URL}?page=${page}`;
const response = await fetch(url);
const data = await response.json();
if (!data.levels || data.levels.length === 0) return null;
const userData = data.levels.find(u => u.userId === userId);
return userData || null;
}
async function fetchUserXP() {
const userId = getUserIdFromURL();
if (!userId) {
document.getElementById("xpCounter").innerText = "Missing user ID in URL (?id=...)";
return;
}
try {
let user = null;
let page = 1;
while (!user) {
user = await fetchUserFromPage(userId, page);
if (!user) {
page++;
// Stop after 10 pages to avoid infinite loops
if (page > 10) break;
}
}
if (user) {
document.getElementById("name").innerText = user.user.username;
document.getElementById("xpCounter").innerText = user.xp.toLocaleString();
const avatarImg = document.getElementById("avatarImg");
if (avatarImg) {
avatarImg.src = getAvatarURL(user);
avatarImg.onerror = () => {
avatarImg.onerror = null;
avatarImg.src = "./default.png";
};
}
} else {
document.getElementById("xpCounter").innerText = "User not found in top leaderboard pages.";
}
} catch (error) {
document.getElementById("xpCounter").innerText = "Error loading XP";
console.error("Error fetching XP:", error);
}
}
fetchUserXP();
setInterval(fetchUserXP, 60000);
</script>
</body>
</html>