-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
31 lines (31 loc) · 1.12 KB
/
main.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
$(function () {
const socket = io({transports: ["websocket", "polling"]});
$("body").tooltip({selector: "[data-toggle=tooltip]"});
socket.emit("is online");
socket.emit("get players");
socket.on("get players", data => displayPlayers(data));
socket.on("change", data => displayPlayers(data));
socket.on("online", () => {
$("#status").removeClass("text-danger");
$("#status").addClass("text-success");
socket.emit("get players");
});
socket.on("offline", () => {
$("#status").removeClass("text-success");
$("#status").addClass("text-danger");
$("#players").text(0);
$("#display").addClass("d-none");
$("#display").empty();
});
function displayPlayers(data) {
$("#players").text(data.length);
if (data.length > 0) {
$("#display").empty();
$("#display").removeClass("d-none");
data.forEach(item => $("#display").append(`<img src="https://minotar.net/helm/${item}/56" class="mx-2 rounded" draggable="false" data-toggle="tooltip" data-placement="top" title="${item}">`));
} else {
$("#display").addClass("d-none");
$("#display").empty();
}
}
});