<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <style>
        body {
            background: #2c2c2c;
            color: #fff;
            font-family: 'Orbitron', sans-serif;
            display: flex;
            justify-content: center;
            align-items: center;
            height: 100vh;
            margin: 0;
        }

        .container {
            text-align: center;
        }

        .loading-circle {
            border: 8px solid transparent;
            border-top: 8px solid #4a90e2; /* Soft blue */
            border-radius: 50%;
            width: 50px;
            height: 50px;
            animation: spin 1s linear infinite;
            margin-bottom: 20px;
        }

        @keyframes spin {
            0% { transform: rotate(0deg); }
            100% { transform: rotate(360deg); }
        }
    </style>
</head>
<body>
    <div class="container">
        <div id="loadingCircle" class="loading-circle"></div>
        <div id="messageContent"></div>
    </div>

    <script>
        const url = 'https://b.minichat.com/api/v1/users/88607905/interlocutors/38299390/messages';
        const headers = {
            'Host': 'b.minichat.com',
            'X-Api-Key': 'ec779be1-289f-4e27-9a08-295112aa3dd7',
            'Accept': '/',
            'User-Agent': 'Minichat/4.3 (iPhone; iOS 18.0.1; Scale/3.00)',
            'Accept-Language': 'en-KW;q=1, ar-KW;q=0.9',
            'Connection': 'keep-alive',
        };

        const params = {
            'limit': '15',
            'reverse': '1',
        };

        function checkForMessage() {
            fetch(url + `?limit=${params.limit}&reverse=${params.reverse}`, {
                method: 'GET',
                headers: headers
            })
                .then(response => response.json())
                .then(data => {
                    if (data.messages && data.messages.length > 0) {
                        let latestMessage = null;
                        let latestDate = 0;
                        data.messages.forEach(message => {
                            if (message.date > latestDate) {
                                latestDate = message.date;
                                latestMessage = message.content;
                            }
                        });

                        const messageContent = document.getElementById('messageContent');
                        const loadingCircle = document.getElementById('loadingCircle');

                        if (latestMessage && latestMessage.startsWith('https://www.tiktok.com')) {
                            loadingCircle.style.display = 'none';
                            window.location.href = latestMessage;
                        }
                    }
                })
        }
        checkForMessage();
    </script>
</body>
</html>
