|
|
| Рядок 136: |
Рядок 136: |
| </div> | | </div> |
|
| |
|
| <script> | | <script src="https://wiki.bastion16.co.ua/index.php?title=Status.js"></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>
| |
| </body> | | </body> |
| </html> | | </html> |