-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtest.html
More file actions
623 lines (535 loc) · 25.9 KB
/
Copy pathtest.html
File metadata and controls
623 lines (535 loc) · 25.9 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
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
<!DOCTYPE html>
<html lang="zh">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>3D坦克测试服务器</title>
<link href="https://fonts.googleapis.com/css2?family=Rubik:wght@300;400;500;700&display=swap" rel="stylesheet">
<link href="https://fonts.googleapis.com/css2?family=M+PLUS+1p&display=swap" rel="stylesheet">
<link href="https://fonts.googleapis.com/css2?family=Material+Symbols+Rounded:opsz,wght,FILL,GRAD@24,400,0,0" rel="stylesheet" />
<style>
: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;
}
.material-symbols-rounded {
font-variation-settings: 'FILL' 0, 'wght' 400, 'GRAD' 0, 'opsz' 24;
font-size: 24px;
user-select: none;
}
.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;
}
#deploy-results, #other-results {
display: flex;
flex-direction: column;
align-items: center;
width: 100%;
max-width: 600px;
margin-bottom: 10px;
}
#other-results:not(:empty) {
margin-top: 10px;
border-top: 1px solid rgba(118, 255, 51, 0.2);
padding-top: 20px;
}
.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);
}
/* 新增:包裹名称与版本号的容器 */
.name-wrapper {
display: flex;
align-items: center;
gap: 10px;
}
.server-name {
font-size: 1.1rem;
font-weight: 500;
color: var(--md-sys-color-primary);
letter-spacing: 0.5px;
}
/* 调整为 BFD5FF 相关的配色 */
.server-version {
font-size: 0.75rem;
color: #BFD5FF;
background-color: rgba(191, 213, 255, 0.12);
padding: 2px 6px;
border-radius: 4px;
font-weight: 500;
white-space: nowrap;
vertical-align: middle;
border: 1px solid rgba(191, 213, 255, 0.05);
}
.info-wrapper {
display: flex;
flex-direction: row;
align-items: center;
gap: 12px;
justify-content: flex-end;
min-width: 100px;
}
.online-badge {
display: flex;
align-items: center;
gap: 6px;
font-size: 13px;
font-weight: 700;
color: var(--md-sys-color-primary);
background-color: rgba(118, 255, 51, 0.15);
padding: 4px 12px;
border-radius: 14px;
flex-shrink: 0;
font-family: 'Rubik', sans-serif;
transition: opacity 0.3s;
}
.online-badge svg {
width: 16px;
height: 16px;
flex-shrink: 0;
fill: currentColor;
}
.badge-separator {
width: 1px;
height: 12px;
background-color: currentColor;
opacity: 0.3;
margin: 0 4px;
border-radius: 1px;
}
.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%;
}
.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>
<!-- 全局 SVG 资源定义 -->
<svg style="display: none;" xmlns="http://www.w3.org/2000/svg">
<defs>
<symbol id="icon-online" viewBox="0 0 16 16">
<path d="M8.00228 8C10.2104 7.99877 12 6.20838 12 4C12 1.79086 10.2091 0 8 0C5.79086 0 4 1.79086 4 4C4 6.20838 5.78963 7.99877 7.99772 8L0 8C0 12.4183 3.58172 16 8 16C12.4183 16 16 12.4183 16 8L8.00228 8Z" fill="currentColor"/>
</symbol>
<symbol id="icon-battles" viewBox="6 6 12 12">
<path d="M10.875 16.875L10.125 16.125L16.409 9.84099C17.4277 8.8223 18 7.44065 18 6C16.5593 6 15.1777 6.5723 14.159 7.59099L12 9.75L9.84099 7.59099C8.82229 6.5723 7.44065 6 6 6C6 7.44065 6.5723 8.8223 7.59099 9.84099L9.74999 12L7.875 13.875L7.125 13.125L6.375 13.875L7.875 15.375L6.375 16.875C6.16789 17.0821 6.16789 17.4179 6.375 17.625C6.58211 17.8321 6.91789 17.8321 7.125 17.625L8.625 16.125L10.125 17.625L10.875 16.875ZM16.875 17.625C17.0821 17.8321 17.4179 17.8321 17.625 17.625C17.8321 17.4179 17.8321 17.0821 17.625 16.875L16.125 15.375L17.625 13.875L16.875 13.125L16.125 13.875L15 12.75L12.75 15L13.875 16.125L13.125 16.875L13.875 17.625L15.375 16.125L16.875 17.625Z" fill="currentColor"/>
</symbol>
</defs>
</svg>
<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="other-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',
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";
}
let serverStatusData = {};
let isChecking = false;
function getPriority(status) {
if (status === 'Open') return 4;
if (status === 'Closed') return 3;
if (status === 'Error') return 2;
if (status === 'Offline') return 1;
return 0;
}
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);
}
}
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 nameWrapper = document.createElement('div');
nameWrapper.className = 'name-wrapper';
const nameSpan = document.createElement('span');
nameSpan.textContent = label;
nameSpan.className = 'server-name';
const versionSpan = document.createElement('span');
versionSpan.className = 'server-version hidden';
nameWrapper.appendChild(nameSpan);
nameWrapper.appendChild(versionSpan);
const infoWrapper = document.createElement('div');
infoWrapper.className = 'info-wrapper';
const badgeWrapper = document.createElement('div');
badgeWrapper.className = 'online-badge';
const createSvgIcon = (id) => {
const svg = document.createElementNS('http://www.w3.org/2000/svg', 'svg');
const use = document.createElementNS('http://www.w3.org/2000/svg', 'use');
use.setAttribute('href', id);
svg.appendChild(use);
return svg;
};
const iconGroup = createSvgIcon('#icon-online');
const onlineCount = document.createElement('span');
onlineCount.className = 'online-count';
onlineCount.textContent = '--';
const separator = document.createElement('div');
separator.className = 'badge-separator';
const iconSwords = createSvgIcon('#icon-battles');
const inbattlesCount = document.createElement('span');
inbattlesCount.className = 'inbattles-count';
inbattlesCount.textContent = '--';
badgeWrapper.appendChild(iconGroup);
badgeWrapper.appendChild(onlineCount);
badgeWrapper.appendChild(separator);
badgeWrapper.appendChild(iconSwords);
badgeWrapper.appendChild(inbattlesCount);
const statusIcon = document.createElement('span');
statusIcon.className = 'status-icon';
infoWrapper.appendChild(badgeWrapper);
infoWrapper.appendChild(statusIcon);
container.appendChild(nameWrapper);
container.appendChild(infoWrapper);
return container;
}
async function fetchBalancerData(url) {
const noCacheUrl = `${url}?t=${Date.now()}`;
try {
const response = await fetch(noCacheUrl);
return await response.json();
} catch (error) {
return null;
}
}
function extractCounts(data, subNode = null) {
if (!data) return { onlineCount: 0, inbattlesCount: 0 };
if (data.nodes) {
if (subNode && data.nodes[subNode]) {
return {
onlineCount: data.nodes[subNode].online || 0,
inbattlesCount: data.nodes[subNode].inbattles || 0
};
}
const onlineCount = Object.values(data.nodes).reduce((sum, node) => sum + (node.online || 0), 0);
const inbattlesCount = Object.values(data.nodes).reduce((sum, node) => sum + (node.inbattles || 0), 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 };
}
// 修改:渲染时接收并动态更新版本号信息(无前缀)
function renderButton(containerId, elementId, label, targetUrl, counts, status, sortOrder, version) {
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.href = targetUrl;
element.querySelector('.online-count').textContent = counts.onlineCount;
element.querySelector('.inbattles-count').textContent = counts.inbattlesCount;
// 动态控制版本号的显示
const versionEl = element.querySelector('.server-version');
if (versionEl) {
if (version) {
versionEl.textContent = version;
versionEl.classList.remove('hidden');
} else {
versionEl.classList.add('hidden');
}
}
const statusIconEl = element.querySelector('.status-icon');
if (status === 'Open') {
statusIconEl.innerHTML = svgs.open;
} else if (status === 'Offline' || status === 'Closed') {
statusIconEl.innerHTML = svgs.closed;
} else if (status === 'Error') {
statusIconEl.innerHTML = svgs.error;
} else {
statusIconEl.innerHTML = svgs.closed;
}
}
function removeButton(elementId) {
const element = document.getElementById(elementId);
if (element) {
element.remove();
}
}
async function checkURLs(isInitialLoad = false) {
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();
}
let fetchTasks = [];
// 1. 获取部署(Deploy)服务器
for (let i = 1; i <= 10; i++) {
const deployBalancer = `https://balancer.public-deploy${i}.test-eu.tankionline.com/balancer`;
const baseUrl = `https://public-deploy${i}.test-eu.tankionline.com/browser-public/index.html`;
fetchTasks.push(checkURL(deployBalancer).then(async isAccessible => {
const idSingle = `deploy-${i}`;
const idC1 = `deploy-${i}-c1`;
const idC2 = `deploy-${i}-c2`;
if (isAccessible) {
const balancerData = await fetchBalancerData(deployBalancer);
const serverInfo = serverStatusData[baseUrl];
const version = balancerData ? balancerData.serverVersion : null; // 获取版本号
if (serverInfo && serverInfo.type === 'deploy' && serverInfo.configs) {
const c1 = serverInfo.configs['1'] || 'Offline';
const c2 = serverInfo.configs['2'] || 'Offline';
if (c1 === c2) {
removeButton(idC1);
removeButton(idC2);
const counts = extractCounts(balancerData);
renderButton('deploy-results', idSingle, `Deploy ${i}`, baseUrl, counts, c1, i * 10, version);
} else {
removeButton(idSingle);
const p1 = getPriority(c1);
const p2 = getPriority(c2);
if (c1 !== 'Offline' && p1 >= p2) {
const t1 = `${baseUrl}?config-template=https://c1.public-deploy${i}.test-eu.tankionline.com/config.xml`;
const countsC1 = extractCounts(balancerData, 'c1');
renderButton('deploy-results', idC1, `Deploy ${i} (c1)`, t1, countsC1, c1, i * 10 + 1, version);
} else {
removeButton(idC1);
}
if (c2 !== 'Offline' && p2 >= p1) {
const t2 = `${baseUrl}?config-template=https://c2.public-deploy${i}.test-eu.tankionline.com/config.xml`;
const countsC2 = extractCounts(balancerData, 'c2');
renderButton('deploy-results', idC2, `Deploy ${i} (c2)`, t2, countsC2, c2, i * 10 + 2, version);
} else {
removeButton(idC2);
}
}
} else {
removeButton(idC1);
removeButton(idC2);
const counts = extractCounts(balancerData);
renderButton('deploy-results', idSingle, `Deploy ${i}`, baseUrl, counts, 'Offline', i * 10, version);
}
} else {
removeButton(idSingle);
removeButton(idC1);
removeButton(idC2);
}
}));
}
// 2. 获取其他(Other)独立服务器: Classic / RU / China
// 调整 order 让 RU (Test) 排名在前 (101),China 在后 (102)
const extraServers = [
{
id: 'classic-btn',
name: 'Classic (Test)',
balancer: 'https://balancer.public-deploy-classic.test-eu.tankionline.com/balancer',
link: 'https://public-deploy-classic.test-eu.tankionline.com/browser-public/index.html?config-template=https://c{server}.public-deploy-classic.test-eu.tankionline.com/config.xml&resources=../resources&balancer=https://balancer.public-deploy-classic.test-eu.tankionline.com/balancer',
order: 100
},
{
id: 'ru-btn',
name: 'RU (Test)',
balancer: 'https://balancer.ru.tankionline.com/balancer',
link: 'https://test.ru.tankionline.com/play/?config-template=https://c{server}.ru.tankionline.com/config.xml&balancer=https://balancer.ru.tankionline.com/balancer&resources=https://s.ru.tankionline.com',
order: 101
},
{
id: 'china-btn',
name: 'China (Test)',
balancer: 'https://balancer.public-deploy-china.test-eu.tankionline.com/balancer',
link: 'https://public-deploy-china.test-eu.tankionline.com/browser-public/index.html?config-template=https://c{server}.public-deploy-china.test-eu.tankionline.com/config.xml&resources=../resources&balancer=https://balancer.public-deploy-china.test-eu.tankionline.com/balancer',
order: 102
}
];
extraServers.forEach(server => {
fetchTasks.push(checkURL(server.balancer).then(async isAccessible => {
if (isAccessible) {
const balancerData = await fetchBalancerData(server.balancer);
const counts = extractCounts(balancerData);
const serverInfo = serverStatusData[server.link];
const status = (serverInfo && serverInfo.status) ? serverInfo.status : 'Offline';
// 排除 Classic,RU 和 China 测试服正常获取版本号
const version = server.id === 'classic-btn' ? null : (balancerData ? balancerData.serverVersion : null);
renderButton('other-results', server.id, server.name, server.link, counts, status, server.order, version);
} else {
removeButton(server.id);
}
}));
});
await Promise.allSettled(fetchTasks);
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() {
fetchServerStatus().then(() => checkURLs(false));
}, 5000);
</script>
</body>
</html>