-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathServerInfo.html
More file actions
226 lines (194 loc) · 7.06 KB
/
ServerInfo.html
File metadata and controls
226 lines (194 loc) · 7.06 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
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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>InCraftTime服务器状态</title>
<style>
.server-card {
max-width: 480px;
background: #2c2f33;
border-radius: 12px;
padding: 20px;
margin: 20px;
color: #ffffff;
font-family: Arial, sans-serif;
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}
.status-header {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 15px;
}
.status-indicator {
display: flex;
align-items: center;
}
.status-dot {
width: 12px;
height: 12px;
border-radius: 50%;
margin-right: 10px;
}
.online { background: #3ba55d; }
.offline { background: #ed4245; }
.refresh-btn {
background: #5865f2;
color: white;
border: none;
padding: 8px 16px;
border-radius: 4px;
cursor: pointer;
transition: background 0.3s ease;
}
.refresh-btn:hover { background: #4752c4; }
.refresh-btn:disabled { background: #40444b; cursor: not-allowed; }
.server-info {
margin: 10px 0;
line-height: 1.6;
}
.info-label {
color: #b9bbbe;
margin-right: 8px;
}
.player-list {
background: #202225;
border-radius: 8px;
padding: 10px;
margin-top: 15px;
max-height: 200px;
overflow-y: auto;
}
.loading {
text-align: center;
padding: 20px;
color: #888;
}
.player-percent {
color: #888;
font-size: 0.9em;
margin-left: 8px;
}
.progress-container {
width: 100%;
height: 8px;
background: #202225;
border-radius: 4px;
margin-top: 8px;
overflow: hidden;
}
.progress-bar {
height: 100%;
background: #3ba55d;
border-radius: 4px;
width: 0;
transition: width 0.5s ease, background 0.3s ease;
}
.progress-bar.medium-usage {
background: #faa81a;
}
.progress-bar.high-usage {
background: #ed4245;
}
</style>
</head>
<body>
<div class="server-card">
<div class="status-header">
<div class="status-indicator">
<div class="status-dot offline"></div>
<h2>服务器状态加载中...</h2>
</div>
<button class="refresh-btn" onclick="refreshData()" disabled>刷新</button>
</div>
<div class="loading">正在获取服务器数据...</div>
</div>
<script>
const API_URL = 'https://api.mcstatus.io/v2/status/java/mc.incrafttime.top';
const card = document.querySelector('.server-card');
const refreshBtn = document.querySelector('.refresh-btn');
async function fetchData() {
try {
refreshBtn.disabled = true;
refreshBtn.textContent = '刷新中...';
const response = await fetch(API_URL);
if (!response.ok) throw new Error('请求失败');
const data = await response.json();
updateServerStatus(data);
refreshBtn.disabled = false;
refreshBtn.textContent = '刷新';
} catch (error) {
card.querySelector('.loading').textContent = '数据加载失败';
refreshBtn.disabled = false;
refreshBtn.textContent = '刷新';
console.error('错误详情:', error);
}
}
function refreshData() {
const oldInfo = card.querySelectorAll('.server-info, .player-list');
oldInfo.forEach(element => element.remove());
const loading = document.createElement('div');
loading.className = 'loading';
loading.textContent = '正在刷新数据...';
card.appendChild(loading);
fetchData();
}
function updateServerStatus(data) {
card.querySelectorAll('.loading').forEach(el => el.remove());
const isOnline = data.online;
const statusDot = card.querySelector('.status-dot');
statusDot.className = `status-dot ${isOnline ? 'online' : 'offline'}`;
card.querySelector('h2').innerHTML = `
${data.host} 状态:
<span style="color: ${isOnline ? '#3ba55d' : '#ed4245'}">
${isOnline ? '在线' : '离线'}
</span>
`;
const infoContainer = document.createElement('div');
const online = data.players?.online || 0;
const max = data.players?.max || 0;
const percent = max > 0 ? ((online / max) * 100).toFixed(1) : '0.0';
infoContainer.innerHTML = `
<div class="server-info">
${data.motd?.html || '未知'}
</div>
<div class="server-info">
<span class="info-label">版本:</span>
${data.version?.name_html || '未知'}
</div>
<div class="server-info">
<span class="info-label">在线玩家:</span>
${online}/${max}
<span class="player-percent">(${percent}%)</span>
<div class="progress-container">
<div class="progress-bar" id="player-progress"></div>
</div>
</div>
`;
const progressBar = infoContainer.querySelector('#player-progress');
const percentage = max > 0 ? (online / max) : 0;
progressBar.style.width = `${percentage * 100}%`;
progressBar.className = 'progress-bar';
if (percentage >= 0.9) {
progressBar.classList.add('high-usage');
} else if (percentage >= 0.8) {
progressBar.classList.add('medium-usage');
}
if (isOnline && data.players?.list?.length > 0) {
const playerList = document.createElement('div');
playerList.className = 'player-list';
playerList.innerHTML = `
<div class="info-label">在线玩家列表:</div>
${data.players.list.map(player => `
<div>${player.name_clean}</div>
`).join('')}
`;
infoContainer.appendChild(playerList);
}
card.appendChild(infoContainer);
}
fetchData();
</script>
</body>
</html>