<!DOCTYPE html>
<html lang="pt-br">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>discord.gg/night</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            background-color: #121212;
            color: #1DB954;
            text-align: center;
            padding: 20px;
        }
        .btn {
            background-color: #1DB954;
            border: none;
            padding: 10px 20px;
            color: white;
            font-size: 16px;
            cursor: pointer;
            margin-top: 10px;
            border-radius: 8px;
        }
        .btn:disabled {
            background-color: #555;
            cursor: not-allowed;
        }
        .btn-download {
            background-color: #1DB954;
            color: white;
            font-size: 16px;
            padding: 10px 20px;
            border: none;
            border-radius: 8px;
            cursor: pointer;
            display: none;
            margin-top: 10px;
        }
        .input-text {
            width: 60%;
            padding: 10px;
            font-size: 16px;
            border: 2px solid #1DB954;
            border-radius: 8px;
            background: #222;
            color: #1DB954;
            outline: none;
            margin-top: 10px;
        }
        .input-text:focus {
            border-color: #1DB954;
            box-shadow: 0 0 8px #1DB954;
        }
        .log {
            text-align: left;
            margin: 20px auto;
            width: 80%;
            background: #222;
            padding: 10px;
            border-radius: 5px;
            max-height: 300px;
            overflow-y: auto;
            white-space: pre-wrap;
        }
        .popup {
            display: none;
            position: fixed;
            top: 50%;
            left: 50%;
            transform: translate(-50%, -50%);
            background: #222;
            color: #1DB954;
            padding: 20px;
            border-radius: 10px;
            box-shadow: 0 0 10px rgba(0, 0, 0, 0.5);
            text-align: center;
            font-size: 18px;
            opacity: 0;
            transition: opacity 1s ease-in-out;
        }
        .popup.fade-in {
            display: block;
            opacity: 1;
        }
        .popup.fade-out {
            opacity: 0;
        }
    </style>
</head>
<body>
    <h1>Gerador de Links Spotify</h1>
    <p>Quantos links você quer gerar?</p>
    <input type="number" class="input-text" id="quantidade" placeholder="Digite um número" min="1" max="5000">
    <button class="btn" id="gerarBtn" onclick="gerarLinks()">Gerar</button>
    <div class="log" id="log"></div>
    <div class="popup" id="popup">Todos os links foram gerados com sucesso!</div>
    <a id="download" class="btn-download" href="#">Baixar Arquivo</a>

    <script>
        function gerarCodigo() {
            const caracteres = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
            let codigo = "";
            for (let i = 0; i < 10; i++) {
                codigo += caracteres.charAt(Math.floor(Math.random() * caracteres.length));
            }
            return codigo;
        }

        async function gerarLinks() {
            const quantidade = parseInt(document.getElementById('quantidade').value);
            const log = document.getElementById('log');
            const gerarBtn = document.getElementById('gerarBtn');
            const popup = document.getElementById('popup');
            const downloadLink = document.getElementById('download');
            log.innerHTML = "";
            gerarBtn.disabled = true;

            if (isNaN(quantidade) || quantidade <= 0 || quantidade > 5000) {
                log.innerHTML = "<p style='color: red;'>Por favor, insira um número válido (entre 1 e 5000).</p>";
                gerarBtn.disabled = false;
                return;
            }

            const links = [];
            for (let i = 0; i < quantidade; i++) {
                const codigo = gerarCodigo();
                const link = `https://www.spotify.com/br-pt/ppt/microsoft/?code=${codigo}`;
                links.push(link);
                log.innerHTML += `${i + 1}. ${codigo}\n`;
                await new Promise(resolve => setTimeout(resolve, 10));
            }

            const blob = new Blob([links.join("\n")], { type: "text/plain" });
            const url = URL.createObjectURL(blob);
            downloadLink.href = url;
            downloadLink.download = `GeradorNight-Spotify [${Math.floor(Math.random() * 10000)}].txt`;
            downloadLink.style.display = "inline-block";

            popup.classList.add('fade-in');
            setTimeout(() => {
                popup.classList.add('fade-out');
            }, 3000);

            setTimeout(() => {
                popup.style.display = "none";
                popup.classList.remove('fade-in', 'fade-out');
            }, 4000);

            gerarBtn.disabled = false;
        }

        document.getElementById("quantidade").addEventListener("keydown", function(event) {
            if (event.key === "Enter") {
                gerarLinks();
            }
        });
    </script>
</body>
</html>
