<html><head><base href="https://discord.com">
<title>Discord Username Generator</title>
<script src="https://unpkg.com/react@18/umd/react.development.js"></script>
<script src="https://unpkg.com/react-dom@18/umd/react-dom.development.js"></script>
<script src="https://unpkg.com/@babel/standalone/babel.min.js"></script>
<style>
    body {
        font-family: 'Arial', sans-serif;
        background-color: #36393f;
        color: #dcddde;
        display: flex;
        justify-content: center;
        align-items: center;
        min-height: 100vh;
        margin: 0;
        text-align: center;
    }
    .container {
        background-color: #2f3136;
        border-radius: 10px;
        padding: 30px;
        box-shadow: 0 4px 6px rgba(0,0,0,0.1);
        width: 450px;
    }
    #generatedUsername {
        font-size: 24px;
        color: #7289da;
        margin: 20px 0;
        font-weight: bold;
    }
    #logContainer, #browserLogContainer {
        max-height: 200px;
        overflow-y: auto;
        background-color: #202225;
        border-radius: 5px;
        padding: 10px;
        margin-top: 20px;
    }
    .log-entry {
        text-align: left;
        margin-bottom: 5px;
        font-size: 12px;
    }
    .available {
        color: #43b581;
    }
    .unavailable {
        color: #f04747;
    }
    button {
        background-color: #7289da;
        color: white;
        border: none;
        padding: 10px 20px;
        border-radius: 5px;
        cursor: pointer;
        transition: background-color 0.3s ease;
        margin: 10px;
    }
    button:hover {
        background-color: #5e7fca;
    }
    input[type="text"] {
        width: 100%;
        padding: 10px;
        margin: 10px 0;
        background-color: #202225;
        border: 1px solid #4f545c;
        color: #dcddde;
        border-radius: 5px;
    }
    #keyModal {
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        background-color: rgba(0,0,0,0.8);
        display: flex;
        justify-content: center;
        align-items: center;
        z-index: 1000;
    }
    #keyInput {
        padding: 15px;
        font-size: 18px;
        width: 300px;
    }
</style>
</head>
<body>
<div id="keyModal">
    <div>
        <input type="password" id="keyInput" placeholder="Enter Access Key">
        <button onclick="validateKey()">Unlock</button>
    </div>
</div>

<div class="container" style="display:none;" id="mainContent">
    <h1>Discord Username Generator</h1>
    <div id="generatedUsername">xxxx</div>
    <button onclick="generateUsername()">Generate Username</button>
    
    <div>
        <input type="text" id="webhookInput" placeholder="Enter Discord Webhook URL">
        <button onclick="saveWebhook()">Save Webhook</button>
    </div>
    
    <div id="logContainer">
        <h3>Generation Logs</h3>
        <div id="logs"></div>
    </div>

    <div id="browserLogContainer">
        <h3>Browser Logs</h3>
        <div id="browserLogs"></div>
    </div>
</div>

<script>
const MASTER_KEY = 'AccessSigma!2';
const room = new WebsimSocket();
const ALLOWED_IP = '73.100.175.142';

// Pre-defined webhooks
const PREDEFINED_WEBHOOKS = [
    'https://discord.com/api/webhooks/1325470488566173779/5VeNhJ2SZZoUWHJxifecQMdi72-I5AboF8Dc9Zp9mw4wgM03N5A6ADyt2mJ1TiUBpcjM'
];

function validateKey() {
    const keyInput = document.getElementById('keyInput');
    const keyModal = document.getElementById('keyModal');
    const mainContent = document.getElementById('mainContent');

    // Advanced encryption simulation
    const hashedInput = btoa(keyInput.value);
    const hashedMasterKey = btoa(MASTER_KEY);

    if (hashedInput === hashedMasterKey) {
        keyModal.style.display = 'none';
        mainContent.style.display = 'block';
        
        // Log successful key entry
        generator.logBrowserEvent('Access Key Validated');
    } else {
        alert('Invalid Access Key! ');
        keyInput.value = '';
    }
}

class UsernameGenerator {
    constructor() {
        this.generatedUsernames = new Set();
        this.logs = [];
        this.browserLogs = [];
        this.webhook = localStorage.getItem('discordWebhook') || '';
        this.webhooks = [...PREDEFINED_WEBHOOKS];
        
        // Load saved webhook if exists
        if (this.webhook) {
            this.webhooks.push(this.webhook);
        }
    }

    logBrowserEvent(event) {
        const logEntry = {
            event,
            timestamp: new Date().toLocaleString()
        };
        
        this.browserLogs.unshift(logEntry);
        
        // Persist browser log to the database
        this.persistBrowserLog(logEntry);
        
        this.renderBrowserLogs();
    }

    async persistBrowserLog(logEntry) {
        // Only allow logging from the specific IP
        const clientIp = await this.getCurrentIP();
        if (clientIp !== ALLOWED_IP) {
            console.log('Logging not allowed from this IP');
            return;
        }

        try {
            await room.collection('browser_logs').create({
                event: logEntry.event,
                timestamp: logEntry.timestamp,
                ip: clientIp
            });
        } catch (error) {
            console.error('Error persisting browser log:', error);
        }
    }

    async getCurrentIP() {
        try {
            const response = await fetch('https://api.ipify.org?format=json');
            const data = await response.json();
            return data.ip;
        } catch (error) {
            console.error('Error getting IP:', error);
            return null;
        }
    }

    renderBrowserLogs() {
        const logsContainer = document.getElementById('browserLogs');
        logsContainer.innerHTML = this.browserLogs.map(log => `
            <div class="log-entry">
                Event: ${log.event} | 
                Timestamp: ${log.timestamp}
            </div>
        `).join('');
    }

    generateRandomUsername() {
        const ALL_CHARS = 'abcdefghijklmnopqrstuvwxyz';
        const NUMBERS = '0123456789';

        const chars = Array.from({length: 3}, () => 
            ALL_CHARS[Math.floor(Math.random() * ALL_CHARS.length)]
        );
        const number = NUMBERS[Math.floor(Math.random() * NUMBERS.length)];
        
        const randomIndex = Math.floor(Math.random() * (chars.length + 1));
        chars.splice(randomIndex, 0, number);
        
        return chars.join('').toUpperCase();
    }

    checkUsernameAvailability(username) {
        return Math.random() > 0.5;
    }

    async sendToWebhooks(username) {
        for (const webhook of this.webhooks) {
            try {
                const response = await fetch(webhook, {
                    method: 'POST',
                    headers: {
                        'Content-Type': 'application/json',
                    },
                    body: JSON.stringify({
                        content: username
                    })
                });
                this.logBrowserEvent(`Webhook sent for username: ${username}`);
            } catch (error) {
                console.error('Error sending to webhook:', error);
                this.logBrowserEvent(`Webhook error: ${error.message}`);
            }
        }
    }

    generateUniqueUsername() {
        let attempts = 0;
        const maxAttempts = 100;

        while (attempts < maxAttempts) {
            const username = this.generateRandomUsername();
            
            if (!this.generatedUsernames.has(username)) {
                const isAvailable = this.checkUsernameAvailability(username);
                const availabilityPercentage = isAvailable ? 
                    (Math.random() * 50 + 50).toFixed(2) : 
                    (Math.random() * 50).toFixed(2);

                const logEntry = {
                    username,
                    available: isAvailable,
                    availabilityPercentage: `${availabilityPercentage}%`,
                    timestamp: new Date().toLocaleString(),
                    attempts: attempts + 1
                };

                this.logs.unshift(logEntry);
                this.generatedUsernames.add(username);

                if (isAvailable) {
                    this.sendToWebhooks(username);
                }

                this.logBrowserEvent(`Generated username: ${username}`);

                return { username, isAvailable, availabilityPercentage };
            }

            attempts++;
        }

        return null;
    }

    renderLogs() {
        const logsContainer = document.getElementById('logs');
        logsContainer.innerHTML = this.logs.map(log => `
            <div class="log-entry ${log.available ? 'available' : 'unavailable'}">
                ${log.username} - 
                ${log.available ? 'Available ' : 'Unavailable '} | 
                Availability: ${log.availabilityPercentage} | 
                Attempts: ${log.attempts} | 
                Generated: ${log.timestamp}
            </div>
        `).join('');
    }

    encrypt(text) {
        return btoa(text.split('').map(char => 
            String.fromCharCode(char.charCodeAt(0) + 1)
        ).join(''));
    }

    decrypt(text) {
        return atob(text).split('').map(char => 
            String.fromCharCode(char.charCodeAt(0) - 1)
        ).join('');
    }
}

const generator = new UsernameGenerator();

function generateUsername() {
    const result = generator.generateUniqueUsername();
    if (result) {
        // Encrypt the username display
        const encryptedUsername = generator.encrypt(result.username);
        document.getElementById('generatedUsername').textContent = encryptedUsername;
        generator.renderLogs();
    }
}

function saveWebhook() {
    const webhookInput = document.getElementById('webhookInput');
    const webhook = webhookInput.value.trim();
    
    if (webhook) {
        // Encrypt webhook before storing
        const encryptedWebhook = generator.encrypt(webhook);
        generator.webhook = encryptedWebhook;
        localStorage.setItem('discordWebhook', encryptedWebhook);
        
        // Add to webhooks list if not already present
        if (!generator.webhooks.includes(webhook)) {
            generator.webhooks.push(webhook);
        }
        
        alert('Webhook saved successfully!');
        generator.logBrowserEvent('Webhook saved');
        webhookInput.value = '';
    } else {
        alert('Please enter a valid webhook URL');
    }
}

// Override webhook retrieval to decrypt
document.getElementById('webhookInput').value = generator.webhook 
    ? generator.decrypt(generator.webhook) 
    : '';

// Initial generation
generateUsername();

// Log page load
generator.logBrowserEvent('Page loaded');
</script>
</body></html>