<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Z3US Discord Webhook Tool</title>
    <meta name="description" content="Z3US Discord Webhook Tool - Webhook Info, Webhook Spammer, Batch Sender, Embed Creator and Delete Webhook in only one Website ">
    <link rel="icon" href="./Assets/main.png" type="image/png">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0-beta3/css/all.min.css">
    <link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
    <link href="./Assets/main.css" rel="stylesheet">
</head>
<body>
    <div class="header">
        <button id="darkModeToggle" onclick="toggleDarkMode()">
            <span class="icon">
                <i class="material-icons" id="darkModeIcon">dark_mode</i>
            </span>
        </button>
        <button id="webhookInfoTab" onclick="switchTab('webhookInfo')" class="active">
            <span class="icon"><i class="fas fa-info-circle"></i></span> Webhook Info
        </button>          
        <button id="singleTab" onclick="switchTab('single')">
            <span class="icon"><i class="fas fa-paper-plane"></i></span> Webhook Spammer
        </button>
        <button id="batchTab" onclick="switchTab('batch')">
            <span class="icon"><i class="fas fa-clipboard-list"></i></span> Batch Sender
        </button>
        <button id="embedTab" onclick="switchTab('embed')">
            <span class="icon"><i class="fas fa-image"></i></span> Embed Creator
        </button>
        <button id="deleteTab" onclick="switchTab('delete')">
            <span class="icon"><i class="fas fa-trash-alt"></i></span> Delete Webhook
        </button>
        <button id="settingsTab" onclick="switchTab('settings')">
            <span class="icon"><i class="fas fa-cogs"></i></span> Settings
        </button>      
        <button id="discord" onclick="opendiscord()" onmouseover="hoverDiscord(true)" onmouseout="hoverDiscord(false)">
            <span class="icon"><i class="fa-brands fa-discord"></i></span>
        </button>
     
    </div>

    <div class="container">
        <div id="webhookInfo" class="tab-content active">
            <h2>Webhook Information</h2>
            <input type="text" id="webhookUrlInput" placeholder="Enter Discord Webhook URL" onchange="fetchWebhookInfo()">
            <button onclick="fetchWebhookInfo()">Get Webhook Info</button>

            <div id="webhookDetails" style="display: none;">
                <h3>Webhook Details</h3>
                <p><strong>Name:</strong> <span id="webhookName">N/A</span></p>
                <p><strong>Webhook ID:</strong> <span id="webhookId">N/A</span></p>
                <p><strong>Webhook Token:</strong> <span id="webhookToken">N/A</span></p>
                <p><strong>Channel ID:</strong> <span id="channelId">N/A</span></p>
                <p><strong>Guild ID:</strong> <span id="guildId">N/A</span></p>
            </div>
            <p id="webhookStatus"></p>
        </div>

        <div id="single" class="tab-content">
            <h2>Webhook Spammer</h2>
            <input type="text" id="singleWebhook" placeholder="Enter Discord Webhook URL">
            <textarea id="singleMessage" placeholder="Enter the message"></textarea>
            <input type="number" id="singleTimes" placeholder="Number of times to send">
            <div class="slider-container">
                <label for="delaySlider">Delay (ms):</label>
                <input type="range" id="delaySlider" class="slider" min="0" max="1000" value="500" step="10">
                <span class="slider-value" id="delayValue">500</span>
            </div>
            <br/><br/>
            <button onclick="sendSingleWebhook()">Send</button>
            <p id="singleStatus"></p>
        </div>

        <div id="batch" class="tab-content">
            <h2>Batch Webhook Sender</h2>
            <textarea id="batchWebhooks" placeholder="Enter multiple Discord Webhook URLs (one per line)"></textarea>
            <textarea id="batchMessage" placeholder="Enter the message"></textarea>
            <input type="number" id="batchTimes" placeholder="Number of times to send each message">
            <button onclick="sendBatchWebhooks()">Send Batch</button>
            <p id="batchStatus"></p>
        </div>

        <div id="embed" class="tab-content">
            <h2>Embed Creator</h2>
            <input type="text" id="embedWebhook" placeholder="Enter Discord Webhook URL">

            <h3>Embed Content</h3>
            <input type="text" id="embedTitle" placeholder="Embed Title (optional)">
            <textarea id="embedDescription" placeholder="Embed Description (optional)"></textarea>
            <textarea id="embedContent" placeholder="Content (outside embed)"></textarea>

            <h3>Embed Settings</h3>
            <div>Embed Color:</div>
            <input type="color" id="embedColor" value="#ff0000" placeholder="Embed Color">
            <input type="text" id="embedURL" placeholder="URL for image or link (optional)">
            <input type="datetime-local" id="embedTimestamp" placeholder="Timestamp">
            <input type="text" id="embedFooter" placeholder="Footer text (optional)">
            <input type="text" id="embedThumbnail" placeholder="Thumbnail Image URL (optional)">
            <input type="text" id="embedImage" placeholder="Image URL (optional)">
            <input type="text" id="embedAuthor" placeholder="Author (optional)">
            <input type="text" id="embedIcon" placeholder="Author Icon URL (optional)">
            <h3>Fields</h3>
            <textarea id="embedFields" placeholder="Enter fields like: title|description (one per line)"></textarea>
            <button onclick="sendEmbed()">Send Embed</button>
            <p id="embedStatus"></p>
        </div>

        <div id="settings" class="tab-content">
            <h2>Settings</h2>
            <input type="text" id="botName" placeholder="Enter Bot Name">
            <input type="text" id="profilePicture" placeholder="Enter Profile Picture URL (optional)">
            <button onclick="saveSettings()">Save</button>
            <p id="settingsStatus"></p>
        </div>

        <div id="delete" class="tab-content">
            <h2>Delete Webhook</h2>
            <input type="text" id="deleteWebhook" placeholder="Enter Discord Webhook URL to delete">
            <button onclick="deleteWebhook()">Delete</button>
            <p id="deleteStatus"></p>
        </div>
    </div>

    <script>
        ///////////\\\\\\\\\\
        //-- DelaySlider --\\
        ///////////\\\\\\\\\\
        const delaySlider = document.getElementById('delaySlider');
        const delayValue = document.getElementById('delayValue');
        delaySlider.addEventListener('input', function() {
            delayValue.textContent = delaySlider.value;
        });

        ///////////\\\\\\\\\\
        //-- ColorPicker --\\
        ///////////\\\\\\\\\\
        const colorPicker = document.getElementById('embedColor');
        const embedColorElement = document.getElementById('embedColor');
        colorPicker.addEventListener('input', function() {
            embedColorElement.style.backgroundColor = colorPicker.value;
        });

        ////////////\\\\\\\\\\
        //-- Tabswitching --\\
        ////////////\\\\\\\\\\
        function switchTab(tabId) {
            document.querySelectorAll('.tab-content').forEach(tab => tab.classList.remove('active'));
            document.getElementById(tabId).classList.add('active');

            document.querySelectorAll('.header button').forEach(button => button.classList.remove('active'));
            document.getElementById(tabId + 'Tab').classList.add('active');
        }

        //////////\\\\\\\
        //-- Discord --\\
        //////////\\\\\\\
        function hoverDiscord(isHovered) {
            const discordIcon = document.querySelector("#discord i");

            if (isHovered) {
                discordIcon.style.transform = "scale(1.25)"
                discordIcon.style.transition = "transform 0.3s ease-in-out";
            } else {
                discordIcon.style.transform = "scale(1)"
            }
        }

        function opendiscord() {
            const discordLink1 = "https://discord.com/invite/VaMhJXgr2M";
            const discordLink2 = "https://discord.com/invite/79ttSvSS28";

            const landingPage = `
                <html>
                    <head>
                        <link rel="icon" href="./Assets/main.png" type="image/png">
                        <title>Z3US | Discord Invites</title>
                        <style>
                            body {
                                font-family: 'Arial', sans-serif;
                                background-color: #121212;
                                color: #f3f4f6;
                                display: flex;
                                flex-direction: column;
                                justify-content: center;
                                align-items: center;
                                height: 100vh;
                                margin: 0;
                            }
                            .container {
                                background-color: #1e1e1e;
                                border-radius: 10px;
                                box-shadow: 0 0 50px rgba(0, 86, 229, 0.8);
                                padding: 40px;
                                text-align: center;
                                width: 80%;
                                max-width: 500px;
                            }
                            h1 {
                                font-size: 2.5rem;
                                margin-bottom: 20px;
                                color: #ffffff;
                            }
                            p {
                                font-size: 1.1rem;
                                margin-bottom: 25px;
                            }
                            a {
                                display: inline-block;
                                background-color: #5865f2;
                                color: white;
                                padding: 16px 28px;
                                text-decoration: none;
                                border-radius: 12px;
                                font-size: 1.2rem;
                                margin: 10px 0;
                                transition: box-shadow 0.5s ease, background-color 0.3s ease, transform 0.3s ease;
                            }

                            a:hover {
                                background-color: #4752c4;
                                transform: scale(1.05);
                                box-shadow: 0 0 100px rgba(0, 86, 229, 0.8);
                            }
                            .discord-logo {
                                width: 40px;
                                vertical-align: middle;
                                margin-right: 10px;
                                border-radius: 5px;
                            }
                            footer {
                                margin-top: 30px;
                                font-size: 0.9rem;
                                color: #888;
                            }
                        </style>
                    </head>
                    <body>
                        <div class="container">
                            <h1>Our Discord Servers</h1>
                            <p>
                                <a href="${discordLink1}" target="_blank">
                                    <img src="https://i.imgur.com/2vLWEgH.png" class="discord-logo" alt="Discord Logo"> Z3US Projects | Random Stuff
                                </a>
                            </p>
                            <p>
                                <a href="${discordLink2}" target="_blank">
                                    <img src="https://i.imgur.com/gLwCiUc.png" class="discord-logo" alt="Discord Logo"> Zypherion | Roblox Scripts
                                </a>
                            </p>
                            <footer>
                                <p>Made with love <3</p>
                            </footer>
                        </div>
                    </body>
                </html>
            `;
            
            const newWindow = window.open();
            newWindow.document.write(landingPage);
        }




        //////////\\\\\\\\
        //-- Darkmode --\\
        //////////\\\\\\\\
        function toggleDarkMode() {
            const body = document.body;
            const icon = document.getElementById('darkModeIcon');

            body.classList.toggle('dark-mode');

            if (body.classList.contains('dark-mode')) {
                icon.textContent = 'wb_sunny';
                icon.style.transform = 'rotate(360deg)';
                icon.style.opacity = '1';
            } else {
                icon.textContent = 'dark_mode';
                icon.style.transform = 'rotate(0deg)';
                icon.style.opacity = '1';
            }
        }

        /////////////////\\\\\\\\\\\\\\\
        //-- Single Webhook Sending --\\
        /////////////////\\\\\\\\\\\\\\\
        let botName = "Z3USONTOP";
        let profilePicture = "";

        async function sendSingleWebhook() {
            const webhook = document.getElementById('singleWebhook').value;
            const message = document.getElementById('singleMessage').value;
            const times = parseInt(document.getElementById('singleTimes').value);
            const delay = parseInt(delaySlider.value);

            if (!webhook || !message || !times) {
                document.getElementById('singleStatus').innerHTML = `<span class='error'>All fields are required!</span>`;
                return;
            }

            document.getElementById('singleStatus').innerHTML = "Sending messages...";

            for (let i = 0; i < times; i++) {
                const response = await fetch(webhook, {
                    method: 'POST',
                    headers: { 'Content-Type': 'application/json' },
                    body: JSON.stringify({ username: botName, content: message })
                });

                if (!response.ok) {
                    document.getElementById('singleStatus').innerHTML = `<span class='error'>Failed to send messages! Check the webhook URL.</span>`;
                    return;
                }

                if (i < times - 1) {
                    await new Promise(resolve => setTimeout(resolve, delay));
                }
            }

            document.getElementById('singleStatus').innerHTML = `<span class='success'>Messages sent successfully!</span>`;
        }

        /////////////\\\\\\\\\\
        //-- Batch Sending --\\
        /////////////\\\\\\\\\\
        async function sendBatchWebhooks() {
            const webhooks = document.getElementById('batchWebhooks').value.split('\n').map(url => url.trim()).filter(url => url);
            const message = document.getElementById('batchMessage').value;
            const times = parseInt(document.getElementById('batchTimes').value);

            if (!webhooks.length || !message || !times) {
                document.getElementById('batchStatus').innerHTML = `<span class='error'>All fields are required!</span>`;
                return;
            }

            document.getElementById('batchStatus').innerHTML = "Sending batch messages...";

            for (const webhook of webhooks) {
                for (let i = 0; i < times; i++) {
                    const response = await fetch(webhook, {
                        method: 'POST',
                        headers: { 'Content-Type': 'application/json' },
                        body: JSON.stringify({
                            username: botName,
                            content: message,
                            avatar_url: profilePicture || undefined
                        })
                    });

                    if (!response.ok) {
                        document.getElementById('batchStatus').innerHTML = `<span class='error'>Failed to send messages to one or more webhooks! Check the URLs.</span>`;
                        return;
                    }
                }
            }

            document.getElementById('batchStatus').innerHTML = `<span class='success'>Batch messages sent successfully!</span>`;
        }

        /////////////\\\\\\\\\\
        //-- Embed Sending --\\
        /////////////\\\\\\\\\\
        async function sendEmbed() {
            const webhook = document.getElementById('embedWebhook').value;
            const title = document.getElementById('embedTitle').value;
            const description = document.getElementById('embedDescription').value;
            const content = document.getElementById('embedContent').value;
            const color = document.getElementById('embedColor').value;
            const url = document.getElementById('embedURL').value;
            const timestamp = document.getElementById('embedTimestamp').value;
            const footer = document.getElementById('embedFooter').value;
            const thumbnail = document.getElementById('embedThumbnail').value;
            const image = document.getElementById('embedImage').value;
            const author = document.getElementById('embedAuthor').value;
            const icon = document.getElementById('embedIcon').value;
            const fields = document.getElementById('embedFields').value.split('\n').map(f => f.split('|')).filter(f => f.length === 2);

            if (!webhook) {
                document.getElementById('embedStatus').innerHTML = `<span class='error'>Webhook URL is required!</span>`;
                return;
            }

            const embed = {
                title: title || undefined,
                description: description || undefined,
                color: parseInt(color.replace('#', ''), 16),
                url: url || undefined,
                timestamp: timestamp ? new Date(timestamp).toISOString() : undefined,
                footer: footer ? { text: footer } : undefined,
                thumbnail: thumbnail ? { url: thumbnail } : undefined,
                image: image ? { url: image } : undefined,
                author: author ? { name: author, icon_url: icon } : undefined,
                fields: fields.map(f => ({
                    name: f[0],
                    value: f[1],
                    inline: f.length > 2 ? f[2] === 'true' : false
                }))
            };

            const requestData = {
                username: botName,
                avatar_url: profilePicture || undefined,
                content: content || undefined,
                embeds: [embed]
            };

            const response = await fetch(webhook, {
                method: 'POST',
                headers: { 'Content-Type': 'application/json' },
                body: JSON.stringify(requestData)
            });

            if (response.ok) {
                document.getElementById('embedStatus').innerHTML = `<span class='success'>Embed sent successfully!</span>`;
            } else {
                document.getElementById('embedStatus').innerHTML = `<span class='error'>Failed to send embed! Check the webhook URL.</span>`;
            }
        }

        //////////////\\\\\\\\\\\\
        //-- Webhook Deletion --\\
        //////////////\\\\\\\\\\\\
        async function deleteWebhook() {
            const webhook = document.getElementById('deleteWebhook').value;

            if (!webhook) {
                document.getElementById('deleteStatus').innerHTML = `<span class='error'>Webhook URL is required!</span>`;
                return;
            }

            const response = await fetch(webhook, { method: 'DELETE' });

            if (response.ok) {
                document.getElementById('deleteStatus').innerHTML = `<span class='success'>Webhook deleted successfully!</span>`;
            } else {
                document.getElementById('deleteStatus').innerHTML = `<span class='error'>Failed to delete webhook! Check the URL.</span>`;
            }
        }

        ////////////\\\\\\\\\\
        //-- Webhook Info --\\
        ////////////\\\\\\\\\\
        async function fetchWebhookInfo() {
            const webhookUrl = document.getElementById('webhookUrlInput').value;
            const webhookIdMatch = webhookUrl.match(/\/([0-9]+)\/([a-zA-Z0-9_-]+)/);

            if (webhookIdMatch) {
                const webhookId = webhookIdMatch[1];
                const webhookToken = webhookIdMatch[2];
                
                document.getElementById('webhookId').innerText = webhookId;
                document.getElementById('webhookToken').innerText = webhookToken;

                document.getElementById('webhookStatus').innerText = "Fetching webhook details...";

                try {
                    const response = await fetch(`https://discord.com/api/webhooks/${webhookId}/${webhookToken}`, {
                        method: 'GET',
                        headers: { 'Content-Type': 'application/json' }
                    });

                    if (response.ok) {
                        const webhookData = await response.json();

                        document.getElementById('webhookName').innerText = webhookData.name || 'N/A';
                        document.getElementById('channelId').innerText = webhookData.channel_id || 'N/A';
                        document.getElementById('guildId').innerText = webhookData.guild_id || 'N/A';

                        document.getElementById('webhookDetails').style.display = 'block';
                        document.getElementById('webhookStatus').innerText = "Webhook details fetched successfully!";
                        setTimeout(() => {
                            document.getElementById('webhookStatus').innerText = '';
                        }, 3000);
                    }

                    else {
                        document.getElementById('webhookStatus').innerText = "Failed to fetch webhook details.";
                        document.getElementById('webhookDetails').style.display = 'none';
                    }
                } catch (error) {
                    document.getElementById('webhookStatus').innerText = "Error fetching webhook details.";
                    document.getElementById('webhookDetails').style.display = 'none';
                }
            } else {
                document.getElementById('webhookStatus').innerText = "Invalid webhook URL. Please check the URL format.";
                document.getElementById('webhookDetails').style.display = 'none';
            }
        }

        /////////////\\\\\\\\\\\\
        //-- Settings Saving --\\
        /////////////\\\\\\\\\\\\
        async function saveSettings() {
            const newBotName = document.getElementById('botName').value;
            const newProfilePicture = document.getElementById('profilePicture').value;
            const statusElement = document.getElementById('settingsStatus');

            statusElement.innerHTML = '';

            let statusMessage = '';

            if (newBotName) {
                botName = newBotName;
                statusMessage += `<span class='success'>Bot name updated to "${botName}"!</span><br/><br/>`;
            }

            if (newProfilePicture) {
                profilePicture = newProfilePicture;
                statusMessage += `<span class='success'>Profile picture updated!</span><br/>`;
            }

            statusElement.innerHTML = statusMessage;

            setTimeout(() => {
                statusElement.innerHTML = '';
            }, 3000);
        }
    </script>
</body>
</html>