Шаблон:Онлайн: відмінності між версіями

Матеріал з Бастіон-16
Перейти до навігації Перейти до пошуку
Немає опису редагування
Мітка: Скасовано
Немає опису редагування
 
(Не показані 109 проміжних версій 2 користувачів)
Рядок 1: Рядок 1:
<!DOCTYPE html>
<html>
 
<html lang="uk">
 
<head>
<head>
 
    <script src="/resources/status.js"></script>
    <meta charset="UTF-8">
    <title>MC Онлайн Гравці</title>
 
    <style>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
        #widget {
 
            padding: 1em;
    <title>MC Онлайн Гравці</title>
            box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
 
        }
    <style>
        #players {
 
            font-weight: bold;  
        body {
            list-style: none;
 
            padding: 0;
            font-family: Arial, sans-serif;
            margin: 0;
 
        }
            text-align: center;
        #players li {
 
            display: flex;
        }
            align-items: center;
 
            padding: 5px 0;
        #widget {
            border-bottom: 1px solid #b1b3b6;
 
        }
            border: 2px solid #333;
        #players li:last-child {
 
            border-bottom: none;
            padding: 10px;
        }
 
        #players img {
            width: 300px;
            width: 24px;
 
            height: 24px;
            margin: 20px auto;
            margin-right: 10px;
 
            border-radius: 4px;
            background-color: #f9f9f9;
            border: 1px solid #a2a9b1;
 
        }
        }
        #players a {
 
            text-decoration: none;
        #players {
            color: #555;
 
        }
            list-style: none;
        #players a:hover {
 
            text-decoration: underline;
            padding: 0;
            color: #007bff;
 
        }
        }
        .server-header {
 
            text-align: center;
        #players li {
            margin-bottom: 15px;
 
            box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
            display: flex;
        }
 
        #playerCount {
            align-items: center;
            font-size: 1.2em;
 
            font-weight: bold;
            justify-content: center;
            margin-left: 10px;
 
        }
            margin: 5px 0;
        #server-icon {
 
            width: 64px;
        }
            height: 64px;
 
            display: block;
        #players img {
            float: left;
 
        }
            width: 20px;
        .status-container {
 
            display: flex;
            height: 20px;
            align-items: center;
 
            justify-content: flex-start;
            margin-right: 10px;
        }
 
        .status-indicator {
            border-radius: 4px;
            width: 20px;
 
            height: 20px;
        }
            border-radius: 50%;
 
            margin-right: 10px;
        #server-icon {
            animation: pulse 1.5s infinite;
 
        }
            width: 64px;
        .status-online {
 
            background-color: #4caf50;
            height: 64px;
            box-shadow: 0 0 10px #4caf50;
 
        }
            display: block;
        .status-offline {
 
            background-color: #f44336;
            margin: 0 auto 10px;
            box-shadow: 0 0 10px #f44336;
 
        }
        }
        .status-text {
 
            font-size: 1.2em;
    </style>
            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;
              font-weight: bold;
    color: #0056b3;
    background-color: #000000;
    padding: 20px 10px 10px 10px;
    /* border-radius: 4px; */
    margin-bottom: 1em;
          text-align: center;
            height: 34px;
        }
        #server-ip {
            box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
            width: 21%;
            font-size: 1.2em; */
            margin: 1em 0 auto;
            padding: 10px;
            /* background-color: #f1f1f1; */
            /* border: 1px solid #ccc; */
            display: block;
            cursor: pointer;
            text-align: center;
            /* position: absolute; */
            top: 50%;
            background-color: #fff;
            color: #000;
          } 
        #server-ip:hover {
            background-color: #000;
            color: #fff;
        }
        #anketa {
            box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
            width: 21%;
            font-size: 1.2em; */
            margin: 1em 0 auto;
            padding: 10px;
            /* background-color: #f1f1f1; */
            /* border: 1px solid #ccc; */
            display: block;
            cursor: pointer;
            text-align: center;
            /* position: absolute; */
            top: 50%;
            background-color: #fff;
            color: #000;
            text-decoration: none;
          }
        #anketa:hover {
            background-color: #000;
            color: #fff;
        }
        .link-header {
            display: flex;
            align-items: center;
            justify-content: space-evenly;
        }
    </style>
</head>
</head>
<body>
<body>
 
        <div id="widget">
    <div id="widget">
            <div class="server-header">
 
                <img id="server-icon" src="" alt="Іконка сервера">
        <img id="server-icon" src="" alt="Іконка сервера" style="display: none;">
                <p id="motd" class="info">Завантаження MOTD...</p>
 
            </div>
        <h3 id="motd">Завантаження MOTD...</h3>
            <div class="link-header">
 
            <p id="server-ip" onclick="copyToClipboard('play.bastion16.co.ua')">IP Сервера</p>
        <h3>Онлайн гравці:</h3>
            <a target=”_blank” href="https://bastion16.co.ua/anketa/survey" id="anketa">Анкета</a>
 
            <a target=”_blank” href="https://map.bastion16.co.ua/" id="anketa">Мапа</a>
        <p id="playerCount">Завантаження...</p>
            <a target=”_blank” href="https://t.me/bastionanketa_bot" id="anketa">Написати адміну</a>
 
            </div>
        <ul id="players"></ul>
            <div class="status-container">
 
                <div id="status-indicator" class="status-indicator status-offline"></div>
    </div>
                <div id="status-text" class="status-text status-offline-text">Offline</div>
 
                <p id="playerCount" class="info">Завантаження...</p>
    <script>
            </div>
 
            <ul id="players"></ul>
        const SERVER_IP = "play.bastion16.co.ua"; // Замініть на вашу IP-адресу або домен
        </div>
 
        
 
        async function fetchServerStatus() {
 
            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 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}/20.png`;
 
                        
 
                        let listItem = document.createElement("li");
 
                        let img = document.createElement("img");
 
                        let 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>";
 
                }
 
                
 
                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>";
 
            }
 
        }
 
        
 
        fetchServerStatus();
 
        setInterval(fetchServerStatus, 30000); // Оновлення кожні 30 секунд
 
    </script>
 
</body>
</body>
</html>
</html>

Поточна версія на 16:08, 20 вересня 2025

MC Онлайн Гравці

Іконка сервера

Завантаження MOTD...

Offline

Завантаження...