Шаблон:Онлайн: відмінності між версіями
Перейти до навігації
Перейти до пошуку
Немає опису редагування |
Немає опису редагування |
||
| Рядок 1: | Рядок 1: | ||
<html> | <!DOCTYPE html> | ||
<html lang="uk"> | |||
<head> | <head> | ||
<meta charset="UTF-8"> | |||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | |||
<title>MC Онлайн Гравці</title> | <title>MC Онлайн Гравці</title> | ||
<style> | <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 { | #widget { | ||
padding: 1em; | padding: 1em; | ||
| Рядок 8: | Рядок 32: | ||
border: 1px solid #c8ccd1; | border: 1px solid #c8ccd1; | ||
border-radius: 4px; | border-radius: 4px; | ||
text-align: center; | |||
} | } | ||
#players { | #players { | ||
| Рядок 29: | Рядок 54: | ||
border-radius: 4px; | border-radius: 4px; | ||
border: 1px solid #a2a9b1; | border: 1px solid #a2a9b1; | ||
} | |||
.server-status { | |||
display: flex; | |||
justify-content: center; | |||
align-items: center; | |||
margin: 10px auto; | |||
} | } | ||
#server-icon { | #server-icon { | ||
| Рядок 34: | Рядок 65: | ||
height: 64px; | height: 64px; | ||
display: block; | display: block; | ||
margin: | margin-right: 15px; | ||
} | |||
.status-indicator { | |||
width: 20px; | |||
height: 20px; | |||
border-radius: 50%; | |||
margin-right: 10px; | |||
animation: pulse 1.5s infinite; | |||
} | } | ||
. | .status-online { | ||
background-color: #4caf50; | |||
box-shadow: 0 0 10px #4caf50; | |||
} | |||
.status-offline { | |||
background-color: #f44336; | |||
box-shadow: 0 0 10px #f44336; | |||
} | |||
.status-text { | |||
font-size: 1em; | |||
font-weight: bold; | |||
} | |||
.status-online-text { | |||
color: #4caf50; | |||
} | |||
.status-offline-text { | |||
color: #f44336; | |||
} | |||
@keyframes pulse { | |||
0%, 100% { | |||
transform: scale(1); | |||
opacity: 1; | |||
} | |||
50% { | |||
transform: scale(1.2); | |||
opacity: 0.7; | |||
} | |||
} | |||
#motd { | |||
font-size: 1.2em; | |||
font-weight: bold; | |||
color: #0056b3; | |||
background-color: #e9f5ff; | |||
padding: 10px; | |||
border: 1px solid #c8e1ff; | |||
border-radius: 4px; | |||
margin-bottom: 1em; | |||
} | } | ||
</style> | </style> | ||
| Рядок 43: | Рядок 116: | ||
<body> | <body> | ||
<div class="mw-body"> | <div class="mw-body"> | ||
<div id="widget"> | <div id="widget"> | ||
<img id="server-icon" src="" alt="Іконка сервера" style="display: none;"> | <div class="server-status"> | ||
<img id="server-icon" src="" alt="Іконка сервера" style="display: none;"> | |||
<div id="status-indicator" class="status-indicator status-offline"></div> | |||
<div id="status-text" class="status-text status-offline-text">Offline</div> | |||
</div> | |||
<p id="motd" class="info">Завантаження MOTD...</p> | <p id="motd" class="info">Завантаження MOTD...</p> | ||
<p id="playerCount" class="info">Завантаження...</p> | <p id="playerCount" class="info">Завантаження...</p> | ||
| Рядок 52: | Рядок 128: | ||
</div> | </div> | ||
<script> | <script> | ||
async function fetchServerStatus() { | |||
const SERVER_IP = "play.bastion16.co.ua"; // Замініть на вашу IP-адресу або домен | |||
try { | |||
console.log("Виконую запит до mcstatus.io..."); | |||
let response = await fetch(`https://api.mcstatus.io/v2/status/java/${SERVER_IP}`); | |||
if (!response.ok) throw new Error(`HTTP помилка! Статус: ${response.status}`); | |||
let data = await response.json(); | |||
console.log("Отримані дані:", data); | |||
// Оновлення індикатора статусу | |||
let statusIndicator = document.getElementById("status-indicator"); | |||
let statusText = document.getElementById("status-text"); | |||
if (data.online) { | |||
statusIndicator.classList.add("status-online"); | |||
statusIndicator.classList.remove("status-offline"); | |||
statusText.classList.add("status-online-text"); | |||
statusText.classList.remove("status-offline-text"); | |||
statusText.innerText = "Online"; | |||
} else { | |||
statusIndicator.classList.add("status-offline"); | |||
statusIndicator.classList.remove("status-online"); | |||
statusText.classList.add("status-offline-text"); | |||
statusText.classList.remove("status-online-text"); | |||
statusText.innerText = "Offline"; | |||
} | |||
// Оновлення MOTD | |||
let motdElement = document.getElementById("motd"); | |||
if (data.motd && Array.isArray(data.motd.html)) { | |||
motdElement.innerHTML = data.motd.html.join(" "); | |||
} else if (data.motd && typeof data.motd.html === "string") { | |||
motdElement.innerHTML = data.motd.html; | |||
} else { | |||
motdElement.innerHTML = "Сервер без MOTD"; | |||
} | |||
// Оновлення кількості гравців | |||
let playerCountElement = document.getElementById("playerCount"); | |||
playerCountElement.innerText = `Гравців онлайн: ${data.players ? data.players.online : 0}`; | |||
// Оновлення списку гравців | |||
let playersElement = document.getElementById("players"); | |||
playersElement.innerHTML = ""; | |||
if (data.players && data.players.online > 0 && data.players.list && data.players.list.length > 0) { | |||
data.players.list.forEach(player => { | |||
let playerName = player.name_raw || player.name; | |||
let playerSkinURL = `https://mineskin.eu/helm/${playerName}/24.png`; | |||
let playerLink = `https://wiki.bastion16.co.ua/index.php?title=${encodeURIComponent(playerName)}`; | |||
let listItem = document.createElement("li"); | |||
let img = document.createElement("img"); | |||
let link = document.createElement("a"); | |||
img.src = playerSkinURL; | |||
img.alt = playerName; | |||
link.href = playerLink; | |||
link.textContent = playerName; | |||
link.target = "_blank"; | |||
listItem.appendChild(img); | |||
listItem.appendChild(link); | |||
playersElement.appendChild(listItem); | |||
}); | |||
} else { | |||
playersElement.innerHTML = "<li>Немає гравців онлайн</li>"; | |||
} | |||
// Оновлення іконки сервера | |||
let 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>"; | |||
// Зробити індикатор червоним у разі помилки | |||
let statusIndicator = document.getElementById("status-indicator"); | |||
let statusText = document.getElementById("status-text"); | |||
statusIndicator.classList.add("status-offline"); | |||
statusIndicator.classList.remove("status-online"); | |||
statusText.classList.add("status-offline-text"); | |||
statusText.classList.remove("status-online-text"); | |||
statusText.innerText = "Offline"; | |||
} | } | ||
} | } | ||
// Ініціалізація | |||
fetchServerStatus(); | |||
setInterval(fetchServerStatus, 10000); // Оновлення кожні 10 секунд | |||
</script> | </script> | ||
</body> | </body> | ||
</html> | </html> | ||
Версія за 14:44, 11 січня 2025
<!DOCTYPE html>
Offline
Завантаження MOTD...
Завантаження...