<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Guest Lock</title>
    <script src="https://cdn.jsdelivr.net/npm/@ygoe/msgpack/msgpack.min.js"></script>
    <style>
        /* Import Google Fonts */
        @import url('https://fonts.googleapis.com/css2?family=Snowburst+One&family=Roboto:wght@400;700&display=swap');

        /* Global Styles */
        body {
            margin: 0;
            font-family: 'Snowburst One', cursive;
            background: linear-gradient(to bottom, #1e3c72, #2a5298); /* Winter-themed gradient */
            color: white;
            overflow: hidden; /* Hide overflow for snowflakes */
        }

        /* Snowflake Animation */
        @keyframes snow {
            0% { transform: translateY(-100px); }
            100% { transform: translateY(100vh); }
        }

        /* Snowflake Style */
        .snowflake {
            position: absolute;
            top: -100px;
            color: white;
            font-size: 1em;
            user-select: none;
            animation: snow 10s linear infinite;
        }

        /* Button Style */
        #guestLockButton {
            padding: 15px 30px;
            font-size: 24px;
            background: rgba(255, 255, 255, 0.2);
            border: 2px solid white;
            border-radius: 10px;
            color: white;
            cursor: pointer;
            font-family: 'Snowburst One', cursive;
            transition: background-color 0.3s ease, transform 0.2s ease;
        }

        #guestLockButton:hover {
            background: white;
            color: #1e3c72;
            transform: scale(1.1);
        }

        /* Counter Style */
        #counters {
            margin-top: 20px;
            font-size: 18px;
            text-align: center;
        }

        #counters div {
            margin: 5px 0;
        }

        /* Center Content */
        .content {
            display: flex;
            flex-direction: column;
            align-items: center;
            justify-content: center;
            height: 100vh;
        }

        /* Snowflake Spawner */
        .snowflake-container {
            pointer-events: none; /* Prevent interaction */
            position: fixed;
            width: 100%;
            height: 100%;
            overflow: hidden;
            top: 0;
            left: 0;
        }
    </style>
</head>
<body>
    <div class="content">
        <button id="guestLockButton">LOCK</button>
        <div id="counters">
            <div id="c">Registered: 0</div>
            <div id="ticks">Made By DogDogDogDogFein/Skapeeeeeee/Kya</div>
        </div>
    </div>

    <!-- Snowflakes Container -->
    <div class="snowflake-container" id="snowflakes"></div>

    <script>
        const ws = new WebSocket("wss://skap.io");
        ws.binaryType = "arraybuffer";

        let accountsRegistered = 0, ticks = 0;

        const updateCounters = () => {
            document.getElementById("c").innerText = `Accounts Registered: ${accountsRegistered}`;
            document.getElementById("ticks").innerText = formatTime(ticks);
        };

        const formatTime = (minutes) => {
            if (minutes < 60) {
                return `${minutes} minute${minutes !== 1 ? 's' : ''} of guest locking.`;
            } else if (minutes < 1440) {
                const hours = Math.floor(minutes / 60);
                return `${hours} hour${hours !== 1 ? 's' : ''} of guest locking.`;
            } else {
                const days = Math.floor(minutes / 1440);
                return `${days} day${days !== 1 ? 's' : ''} of guest locking.`;
            }
        };

        const randomString = (length) => {
            const chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
            return Array.from({ length: length }, () => chars.charAt(Math.floor(Math.random() * chars.length))).join('');
        };

        const workerBlob = new Blob([`
            self.onmessage = (e) => {
                try {
                    const { username, password } = e.data;
                    const combined = username + password;
                    crypto.subtle.digest("SHA-256", new TextEncoder().encode(combined)).then(hash => {
                        const hashHex = Array.from(new Uint8Array(hash))
                            .map(byte => byte.toString(16).padStart(2, "0"))
                            .join("");
                        self.postMessage({ username, passwordHash: hashHex });
                    });
                } catch (error) {
                    self.postMessage({ error: "Hashing error occurred." });
                }
            };
        `], { type: "application/javascript" });

        const worker = new Worker(URL.createObjectURL(workerBlob));

        worker.onmessage = (e) => {
            if (e.data.error) {
                console.error("Worker error:", e.data.error);
                return;
            }
            const { username, passwordHash } = e.data;

            const message = msgpack.serialize({ e: "register", m: { username, password: passwordHash } });
            ws.send(message);

            accountsRegistered++;
            if (accountsRegistered % 150 === 0) ticks++;
            updateCounters();
            console.log(`REGISTERED: ${username}`);
        };

        ws.addEventListener("open", () => {
            console.log("WebSocket connected");
        });

        document.getElementById("guestLockButton").addEventListener("click", () => {
            setInterval(() => {
                const username = `user${randomString(5)}`;
                const password = "ProoklIsVerySigmaNglExDExD";
                worker.postMessage({ username, password });
            }, 1); // Send one registration per second
        });

        // Snowflake Generator
        const createSnowflake = () => {
            const snowflake = document.createElement('div');
            snowflake.classList.add('snowflake');
            snowflake.innerText = '❄';
            snowflake.style.left = Math.random() * 100 + 'vw';
            snowflake.style.fontSize = Math.random() * 2 + 0.5 + 'em';
            snowflake.style.animationDuration = Math.random() * 3 + 7 + 's'; // Between 7-10 seconds
            document.getElementById('snowflakes').appendChild(snowflake);

            // Remove snowflake after animation ends
            setTimeout(() => snowflake.remove(), 10000);
        };

        setInterval(createSnowflake, 200); // Create a snowflake every 200ms
    </script>
</body>
</html>
