-
Notifications
You must be signed in to change notification settings - Fork 1
/
onlineusers.js
45 lines (39 loc) · 1.57 KB
/
onlineusers.js
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
function getUserData() {
let userDataString = localStorage.getItem("userData");
if (!userDataString) {
userDataString = sessionStorage.getItem("userData");
}
return userDataString ? JSON.parse(userDataString) : null;
}
function fetchUserList() {
fetch('https://api.meower.org/ulist')
.then(response => response.json())
.then(data => {
const uList = document.getElementById('online-userlist');
uList.innerHTML = '';
const row = uList.insertRow();
const cell = row.insertCell();
cell.innerHTML = `${data.autoget.length} Online Users:`
cell.colSpan = 2;
cell.style.textAlign = 'center';
cell.style.fontWeight = 'bold';
cell.style.color = '#000000';
cell.style.padding = '5px';
data.autoget.forEach(user => {
const row = uList.insertRow();
const cell = row.insertCell();
const avatarUrl = user.avatar ? `https://uploads.meower.org/icons/${user.avatar}` : '/public/img/defaultpfp.png';
cell.innerHTML = `<img src=${avatarUrl} style="width: 15px; height: 15px; object-fit: cover;" alt="Icon"/>`
const userData = getUserData()
const you = userData.account._id
if (you === user._id) {
cell.innerHTML += ` ${user._id} <------- You`;
} else {
cell.innerHTML += ` ${user._id}`;
}
});
})
.catch(error => console.error("Error fetching online user list:", error));
}
fetchUserList();
setInterval(fetchUserList, 5000);