-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtest.html
More file actions
466 lines (401 loc) · 17.7 KB
/
test.html
File metadata and controls
466 lines (401 loc) · 17.7 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
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
<!DOCTYPE html>
<html lang="zh">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>3D坦克测试服务器</title>
<style>
@import url('https://fonts.googleapis.com/css2?family=Rubik:wght@300;400;500;700&display=swap');
@import url('https://fonts.googleapis.com/css2?family=M+PLUS+1p&display=swap');
:root {
--md-sys-color-primary: #76FF33;
--md-sys-color-on-primary: #001926;
--md-sys-color-background: #001926;
--md-sys-color-surface: rgba(191, 213, 255, 0.08);
--md-sys-color-surface-variant: rgba(191, 213, 255, 0.15);
--md-sys-color-on-surface: #BFD5FF;
--md-sys-motion-easing: cubic-bezier(0.2, 0.0, 0, 1.0);
}
body {
font-family: 'Rubik', 'M PLUS 1p', sans-serif;
margin: 0;
padding-top: 120px;
padding-bottom: 40px;
background-color: var(--md-sys-color-background);
color: var(--md-sys-color-on-surface);
display: flex;
flex-direction: column;
align-items: center;
min-height: 100vh;
box-sizing: border-box;
transition: padding-top 0.3s ease;
}
* {
-webkit-tap-highlight-color: transparent;
box-sizing: border-box;
}
/* Header Styles */
.header {
position: fixed;
top: 0;
width: 100%;
background-color: rgba(0, 25, 38, 0.95);
backdrop-filter: blur(12px);
-webkit-backdrop-filter: blur(12px);
padding: 16px 0;
text-align: center;
z-index: 1000;
border-bottom: 1px solid rgba(191, 213, 255, 0.1);
box-shadow: 0 4px 20px rgba(0,0,0,0.3);
}
.header h1 {
margin: 0;
font-weight: 500;
font-size: 1.5rem;
color: #fff;
letter-spacing: 0.5px;
display: flex;
align-items: center;
justify-content: center;
gap: 12px;
flex-wrap: wrap;
}
.header-subtitle {
font-size: 0.75rem;
color: var(--md-sys-color-primary);
background-color: rgba(118, 255, 51, 0.1);
padding: 4px 10px;
border-radius: 12px;
font-weight: 400;
border: 1px solid rgba(118, 255, 51, 0.3);
vertical-align: middle;
}
/* Server List Card Styles */
#deploy-results, #classic-results {
display: flex;
flex-direction: column;
align-items: center;
width: 100%;
max-width: 600px;
margin-bottom: 10px;
}
#classic-results:not(:empty) {
margin-top: 10px;
border-top: 1px solid rgba(118, 255, 51, 0.2);
padding-top: 20px;
}
/*
修改点:
1. .button-container 是一个 <a> 标签,作为整体点击区域。
2. 移除了原来内部 .button/.server-label 的样式。
3. 新增 .server-name 样式来美化纯文字标题。
*/
.button-container {
display: flex;
align-items: center;
justify-content: space-between;
width: 90%;
background-color: var(--md-sys-color-surface);
margin: 8px 0;
padding: 16px 24px; /* 稍微增加内边距,让卡片看起来更像一个整体 */
border-radius: 16px;
transition: background-color 0.2s, transform 0.2s;
animation: fadeIn 0.5s var(--md-sys-motion-easing);
border: 1px solid transparent;
text-decoration: none;
color: inherit;
cursor: pointer;
}
@keyframes fadeIn {
from { opacity: 0; transform: translateY(10px); }
to { opacity: 1; transform: translateY(0); }
}
.button-container:hover {
background-color: var(--md-sys-color-surface-variant);
border-color: rgba(118, 255, 51, 0.2);
transform: translateY(-2px);
}
/* 新增:纯文字标题样式 */
.server-name {
font-size: 1.1rem;
font-weight: 500;
color: var(--md-sys-color-primary);
letter-spacing: 0.5px;
}
/* Right Side Info Layout - Horizontal */
.info-wrapper {
display: flex;
flex-direction: row;
align-items: center;
gap: 12px;
justify-content: flex-end;
min-width: 100px;
}
/* Icon Container */
.status-icon {
display: flex;
align-items: center;
justify-content: center;
width: 28px;
height: 28px;
flex-shrink: 0;
}
.status-icon svg {
display: block;
width: 100%;
height: 100%;
}
/* Stats Text Container */
.stats-wrapper {
display: flex;
flex-direction: column;
align-items: flex-end;
font-size: 11px;
color: var(--md-sys-color-on-surface);
opacity: 0.8;
line-height: 1.3;
}
.loader {
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
width: 100%;
background-color: var(--md-sys-color-background);
position: fixed;
top: 0;
left: 0;
z-index: 2000;
}
#no-servers {
margin-top: 50px;
font-size: 1.2rem;
opacity: 0.6;
color: var(--md-sys-color-on-surface);
}
.hidden {
display: none !important;
}
</style>
</head>
<body>
<div class="header">
<h1>
<span id="header-title-text">3D坦克测试服务器</span>
<span class="header-subtitle">主页重新设计</span>
</h1>
</div>
<div id="loader" class="loader">
<div data-testid="oval-loading" style="display: flex;padding: 3px;">
<svg width="60" height="60" viewBox="-21.5 -21.5 45 45" xmlns="http://www.w3.org/2000/svg" stroke="#76FF33">
<g fill="none" fill-rule="evenodd">
<g transform="translate(1 1)" stroke-width="3">
<circle stroke-opacity=".2" cx="0" cy="0" r="20" stroke="#76FF33" stroke-width="3"></circle>
<path d="M20 0c0-9.94-8.06-20-20-20">
<animateTransform attributeName="transform" type="rotate" from="0 0 0" to="360 0 0" dur="1s" repeatCount="indefinite"></animateTransform>
</path>
</g>
</g>
</svg>
</div>
</div>
<div id="deploy-results"></div>
<div id="classic-results"></div>
<div id="no-servers" class="hidden">当前暂无服务器</div>
<script>
// --- 语言检测逻辑 ---
const userLang = navigator.language || navigator.userLanguage;
const isChinese = userLang.startsWith('zh');
const texts = {
title: isChinese ? '3D坦克测试服务器' : 'Tanki Online Test Server',
subtitle: isChinese ? '主页重新设计' : 'Homepage Redesign',
loading: isChinese ? '...' : '...',
online: isChinese ? '在线: ' : 'Online: ',
inbattles: isChinese ? '战斗中: ' : 'In Battles: ',
noServers: isChinese ? '当前暂无服务器' : 'No servers available currently'
};
const svgs = {
error: `<svg viewBox="0 0 32 32" fill="none" xmlns="http://www.w3.org/2000/svg"><circle opacity="0.4" cx="16" cy="16" r="16" fill="#FF6666"/><circle cx="16" cy="16" r="12" fill="#FF6666"/><path fill-rule="evenodd" clip-rule="evenodd" d="M14 22V20H18V22H14ZM14 10L14 18H15.3333C16.8061 18 18 16.8061 18 15.3333V10H14Z" fill="#001926"/></svg>`,
open: `<svg viewBox="0 0 30 30" fill="none" xmlns="http://www.w3.org/2000/svg"><circle cx="15" cy="15" r="8" fill="#76FF33"/><circle cx="15" cy="15" r="11.5" stroke="#76FF33" stroke-opacity="0.25" stroke-width="7"/></svg>`,
closed: `<svg viewBox="0 0 48 48" fill="none" xmlns="http://www.w3.org/2000/svg"><path fill-rule="evenodd" clip-rule="evenodd" d="M32 20H35.4477C35.8013 20 36.1405 20.1405 36.3905 20.3905L37.6095 21.6095C37.8595 21.8595 38 22.1987 38 22.5523V37.4477C38 37.8013 37.8595 38.1405 37.6095 38.3905L36.3905 39.6095C36.1405 39.8595 35.8013 40 35.4477 40H12.5523C12.1987 40 11.8595 39.8595 11.6095 39.6095L10.3905 38.3905C10.1405 38.1405 10 37.8013 10 37.4477V22.5523C10 22.1987 10.1405 21.8595 10.3905 21.6095L11.6095 20.3905C11.8595 20.1405 12.1987 20 12.5523 20H16V16C16 11.5817 19.5817 8 24 8C28.4183 8 32 11.5817 32 16V20ZM29 20V16C29 13.2386 26.7614 11 24 11C21.2386 11 19 13.2386 19 16V20H29ZM20 30L24 26L28 30L24 34L20 30Z" fill="#BFD5FF"/></svg>`
};
// 更新静态页面内容
document.title = texts.title;
document.getElementById('header-title-text').textContent = texts.title;
document.querySelector('.header-subtitle').textContent = texts.subtitle;
document.getElementById('no-servers').textContent = texts.noServers;
if (!isChinese) {
document.documentElement.lang = "en";
}
// --- JSON 状态获取逻辑 ---
let serverStatusData = {};
let isChecking = false; // 新增:全局状态锁,防止并发请求
async function fetchServerStatus() {
try {
const response = await fetch(`https://testanki1.github.io/server_status.json?t=${Date.now()}`);
if (response.ok) {
serverStatusData = await response.json();
}
} catch (error) {
console.error("Failed to fetch server status json:", error);
}
}
fetchServerStatus();
setInterval(fetchServerStatus, 60000);
async function checkURL(url) {
const noCacheUrl = `${url}?t=${Date.now()}`;
try {
const response = await fetch(noCacheUrl, { method: 'HEAD' });
return response.ok || response.status === 503;
} catch (error) {
return false;
}
}
// --- 创建按钮元素的逻辑 ---
function createButtonElement(label, link) {
const container = document.createElement('a');
container.className = 'button-container';
container.href = link;
const nameSpan = document.createElement('span');
nameSpan.textContent = label;
nameSpan.className = 'server-name';
const infoWrapper = document.createElement('div');
infoWrapper.className = 'info-wrapper';
const statsWrapper = document.createElement('div');
statsWrapper.className = 'stats-wrapper';
const onlineCount = document.createElement('span');
onlineCount.className = 'online-count';
onlineCount.textContent = '';
const inbattlesCount = document.createElement('span');
inbattlesCount.className = 'inbattles-count';
inbattlesCount.textContent = '';
statsWrapper.appendChild(onlineCount);
statsWrapper.appendChild(inbattlesCount);
const statusIcon = document.createElement('span');
statusIcon.className = 'status-icon';
infoWrapper.appendChild(statsWrapper);
infoWrapper.appendChild(statusIcon);
container.appendChild(nameSpan);
container.appendChild(infoWrapper);
return container;
}
async function fetchCounts(url) {
const noCacheUrl = `${url}?t=${Date.now()}`;
try {
const response = await fetch(noCacheUrl);
const data = await response.json();
if (data.nodes) {
const onlineCount = Object.values(data.nodes).reduce((sum, node) => sum + node.online, 0);
const inbattlesCount = Object.values(data.nodes).reduce((sum, node) => sum + node.inbattles, 0);
return { onlineCount, inbattlesCount };
} else if (data.online !== undefined) {
return {
onlineCount: data.online,
inbattlesCount: data.inbattles !== undefined ? data.inbattles : 0
};
}
return { onlineCount: 0, inbattlesCount: 0 };
} catch (error) {
return { onlineCount: 0, inbattlesCount: 0 };
}
}
async function updateOrAddButton(containerId, elementId, label, targetUrl, balancerUrl, sortOrder) {
// 修复点 1:先获取耗时数据,获取完毕后再去找 DOM
const { onlineCount, inbattlesCount } = await fetchCounts(balancerUrl);
// 获取到数据后,再检查此时页面上是否已经有这个按钮了
const container = document.getElementById(containerId);
let element = document.getElementById(elementId);
if (!element) {
element = createButtonElement(label, targetUrl);
element.id = elementId;
element.style.order = sortOrder;
container.appendChild(element);
}
// 更新人数统计
element.querySelector('.online-count').textContent = `${texts.online}${onlineCount}`;
element.querySelector('.inbattles-count').textContent = `${texts.inbattles}${inbattlesCount}`;
// 更新状态
const statusIconEl = element.querySelector('.status-icon');
let serverInfo = serverStatusData[targetUrl];
if (!serverInfo) {
const altUrl = targetUrl.endsWith('/') ? targetUrl.slice(0, -1) : targetUrl;
serverInfo = serverStatusData[altUrl] || serverStatusData[targetUrl + '/'];
}
if (serverInfo && serverInfo.status) {
if (serverInfo.status === 'Open') {
statusIconEl.innerHTML = svgs.open;
} else if (serverInfo.status === 'Offline' || serverInfo.status === 'Closed') {
statusIconEl.innerHTML = svgs.closed;
} else if (serverInfo.status === 'Error') {
statusIconEl.innerHTML = svgs.error;
} else {
statusIconEl.innerHTML = svgs.closed;
}
} else {
statusIconEl.innerHTML = '';
}
}
function removeButton(elementId) {
const element = document.getElementById(elementId);
if (element) {
element.remove();
}
}
async function checkURLs(isInitialLoad = false) {
// 修复点 2:防止定时器在前一次请求还没结束时,叠加触发重复的检测
if (isChecking) return;
isChecking = true;
const loader = document.getElementById('loader');
const noServersDiv = document.getElementById('no-servers');
try {
if (isInitialLoad) {
loader.style.display = 'flex';
await fetchServerStatus();
}
const promises = [];
// 1. Deploy (1-10)
for (let i = 1; i <= 10; i++) {
const deployBalancer = `https://balancer.public-deploy${i}.test-eu.tankionline.com/balancer`;
const targetUrl = `https://public-deploy${i}.test-eu.tankionline.com/browser-public/index.html`;
const elementId = `deploy-${i}`;
promises.push(checkURL(deployBalancer).then(isAccessible => {
if (isAccessible) {
return updateOrAddButton('deploy-results', elementId, `Deploy ${i}`, targetUrl, deployBalancer, i);
} else {
removeButton(elementId);
}
}));
}
// 2. Classic
const classicBalancer = 'https://test.ru.tankionline.com/status';
const classicLink = 'https://tankiclassic.com/play/';
const classicId = 'classic-btn';
promises.push(checkURL(classicBalancer).then(isAccessible => {
if (isAccessible) {
return updateOrAddButton('classic-results', classicId, 'Classic', classicLink, classicBalancer, 1);
} else {
removeButton(classicId);
}
}));
await Promise.allSettled(promises);
const totalServers = document.querySelectorAll('.button-container').length;
if (totalServers === 0) {
noServersDiv.classList.remove('hidden');
} else {
noServersDiv.classList.add('hidden');
}
if (isInitialLoad) {
loader.style.display = 'none';
}
} finally {
// 执行完毕释放锁,允许下次请求
isChecking = false;
}
}
checkURLs(true);
setInterval(function() {
checkURLs(false);
}, 5000);
</script>
</body>
</html>