Files
SMANAGE/TempLate/API/test.html
T
2026-06-16 11:55:14 +08:00

135 lines
4.2 KiB
HTML

<!DOCTYPE html>
<html lang="zh">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Minecraft服务器状态</title>
<style>
table {
border-collapse: collapse;
width: 100%;
max-width: 800px;
margin: 20px auto;
position: relative;
}
th, td {
border: 1px solid #ddd;
padding: 8px;
text-align: left;
}
th {
background-color: #f2f2f2;
}
.overlay {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-color: rgba(0, 0, 0, 0.7);
color: white;
display: flex;
justify-content: center;
align-items: center;
font-size: 1.2em;
}
.hidden {
display: none;
}
.motd {
font-family: 'Minecraft', sans-serif;
}
</style>
</head>
<body>
<table id="serverStatus">
<thead>
<tr>
<th>项目</th>
<th>值</th>
</tr>
</thead>
<tbody>
<tr>
<td>服务器地址</td>
<td id="host">-</td>
</tr>
<tr>
<td>服务器信息</td>
<td id="motd">-</td>
</tr>
<tr>
<td>延迟</td>
<td id="ping">-</td>
</tr>
<tr>
<td>在线玩家</td>
<td id="players">-</td>
</tr>
<tr>
<td>端口</td>
<td id="port">-</td>
</tr>
<tr>
<td>服务器类型</td>
<td id="type">-</td>
</tr>
<tr>
<td>版本</td>
<td id="version">-</td>
</tr>
</tbody>
</table>
<div id="errorOverlay" class="overlay hidden">
服务器无法访问
</div>
<script>
async function checkServerStatus(serverHost) {
const apiUrl = `https://api.gvsds.com/mcstatus.api?Host=${serverHost}`;
try {
const response = await fetch(apiUrl);
if (!response.ok) {
throw new Error('网络响应不正常');
}
const data = await response.json();
if (data.Error) {
throw new Error(data.Error);
}
// 更新表格数据
document.getElementById('host').textContent = data.Host;
document.getElementById('motd').innerHTML = parseMotd(data.Motd);
document.getElementById('ping').textContent = `${data.Ping}ms`;
document.getElementById('players').textContent = data.Players;
document.getElementById('port').textContent = data.Port;
document.getElementById('type').textContent = data.Type;
document.getElementById('version').textContent = data.Version;
// 隐藏错误掩层
document.getElementById('errorOverlay').classList.add('hidden');
} catch (error) {
console.error('获取服务器状态失败:', error);
// 显示错误掩层
document.getElementById('errorOverlay').classList.remove('hidden');
}
}
// 解析MOTD格式代码(简化版)
function parseMotd(motd) {
// 替换颜色代码为HTML span标签
const withColors = motd.replace(/§([0-9a-fk-or])/g, '<span class="mc-color-$1">');
// 简单处理闭合标签
return withColors + '</span>'.repeat((withColors.match(/<span/g) || []).length);
}
// 示例使用
// 检查mc.gvsds.com服务器状态
checkServerStatus('mc.gvsds.com');
</script>
</body>
</html>