Шаблон:Онлайн: відмінності між версіями
Перейти до навігації
Перейти до пошуку
Немає опису редагування |
Немає опису редагування |
||
| Рядок 1: | Рядок 1: | ||
< | <!DOCTYPE html> | ||
<html lang="uk"> | |||
<head> | |||
<meta charset="UTF-8"> | |||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | |||
<title>MC Онлайн Гравці</title> | |||
<style> | |||
body { | |||
font-family: 'Helvetica Neue', Arial, sans-serif; | |||
margin: 0; | |||
padding: 0; | |||
background-color: #f8f9fa; | |||
color: #202122; | |||
} | |||
.mw-body { | |||
padding: 2em; | |||
max-width: 960px; | |||
margin: 0 auto; | |||
background-color: #ffffff; | |||
border: 1px solid #a2a9b1; | |||
border-radius: 4px; | |||
} | |||
.mw-headline { | |||
font-size: 1.5em; | |||
margin-bottom: 0.5em; | |||
border-bottom: 1px solid #a2a9b1; | |||
padding-bottom: 0.3em; | |||
} | |||
#widget { | |||
padding: 1em; | |||
background-color: #f9f9f9; | |||
border: 1px solid #c8ccd1; | |||
border-radius: 4px; | |||
} | |||
#players { | |||
list-style: none; | |||
padding: 0; | |||
margin: 0; | |||
} | |||
#players li { | |||
display: flex; | |||
align-items: center; | |||
padding: 5px 0; | |||
border-bottom: 1px solid #eaecf0; | |||
} | |||
#players li:last-child { | |||
border-bottom: none; | |||
} | |||
#players img { | |||
width: 24px; | |||
height: 24px; | |||
margin-right: 10px; | |||
border-radius: 4px; | |||
border: 1px solid #a2a9b1; | |||
} | |||
#server-icon { | |||
width: 64px; | |||
height: 64px; | |||
display: block; | |||
margin: 0 auto 10px; | |||
} | |||
.info { | |||
margin: 0.5em 0; | |||
} | |||
</style> | |||
</head> | |||
<body> | |||
<div class="mw-body"> | |||
<h1 class="mw-headline">MC Онлайн Гравці</h1> | |||
<div id="widget"> | |||
<img id="server-icon" src="" alt="Іконка сервера" style="display: none;"> | |||
<p id="motd" class="info">Завантаження MOTD...</p> | |||
<p id="playerCount" class="info">Завантаження...</p> | |||
<ul id="players"></ul> | |||
</div> | |||
</div> | </div> | ||
</ | |||
<script> | |||
const SERVER_IP = "play.bastion16.co.ua"; // Замініть на вашу IP-адресу або домен | |||
const fetchServerStatus = async () => { | |||
try { | |||
console.log("Виконую запит до mcstatus.io..."); | |||
const response = await fetch(`https://api.mcstatus.io/v2/status/java/${SERVER_IP}`); | |||
if (!response.ok) throw new Error(`HTTP помилка! Статус: ${response.status}`); | |||
const data = await response.json(); | |||
console.log("Отримані дані:", data); | |||
const motdElement = document.getElementById("motd"); | |||
motdElement.innerHTML = data.motd?.html?.join(" ") || "Сервер без MOTD"; | |||
const playerCountElement = document.getElementById("playerCount"); | |||
playerCountElement.innerText = `Гравців онлайн: ${data.players?.online || 0}`; | |||
const playersElement = document.getElementById("players"); | |||
playersElement.innerHTML = ""; | |||
if (data.players?.online > 0 && data.players.list?.length > 0) { | |||
data.players.list.forEach(player => { | |||
const playerName = player.name_raw || player.name; | |||
const playerSkinURL = `https://mineskin.eu/helm/${playerName}/24.png`; | |||
const listItem = document.createElement("li"); | |||
const img = document.createElement("img"); | |||
const span = document.createElement("span"); | |||
img.src = playerSkinURL; | |||
img.alt = playerName; | |||
span.textContent = playerName; | |||
listItem.appendChild(img); | |||
listItem.appendChild(span); | |||
playersElement.appendChild(listItem); | |||
}); | |||
} else { | |||
playersElement.innerHTML = "<li>Немає гравців онлайн</li>"; | |||
} | |||
const serverIconElement = document.getElementById("server-icon"); | |||
if (data.icon) { | |||
serverIconElement.src = data.icon; | |||
serverIconElement.style.display = "block"; | |||
} else { | |||
serverIconElement.style.display = "none"; | |||
} | |||
} catch (error) { | |||
console.error("Помилка під час отримання статусу сервера:", error); | |||
document.getElementById("motd").innerText = "Не вдалося завантажити MOTD"; | |||
document.getElementById("playerCount").innerText = "Не вдалося завантажити дані"; | |||
document.getElementById("players").innerHTML = "<li>Помилка завантаження</li>"; | |||
} | |||
}; | |||
fetchServerStatus(); | |||
setInterval(fetchServerStatus, 30000); // Оновлення кожні 30 секунд | |||
</script> | |||
</body> | |||
</html> | |||
Версія за 13:52, 11 січня 2025
<!DOCTYPE html>
MC Онлайн Гравці
Завантаження MOTD...
Завантаження...