<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Proxy Setup</title>
   <style>
        body {
            font-family: Arial, sans-serif;
            margin: 0;
            padding: 0;
            background-color: #1e1e2f;
            color: #e0e0f1;
        }

        .container {
            max-width: 800px;
            margin: 40px auto;
            background-color: #292942;
            padding: 20px;
            border-radius: 8px;
            box-shadow: 0 4px 10px rgba(0, 0, 0, 0.6);
        }

        h1 {
            color: #79b8ff;
            text-align: center;
        }

        .section {
            margin-bottom: 20px;
        }

        label {
            display: block;
            margin-bottom: 5px;
            font-weight: bold;
            color: #a1d8ff;
        }

        select, input[type="text"], input[type="number"], input[type="password"] {
            width: 100%;
            padding: 10px;
            margin-bottom: 10px;
            border: 1px solid #3a3a4f;
            border-radius: 4px;
            background-color: #1c1c2e;
            color: #e0e0f1;
        }

        select:focus, input:focus {
            outline: none;
            border-color: #79b8ff;
        }

        input[type="radio"] {
            margin-right: 8px;
        }

        .dropdowns {
            display: flex;
            gap: 10px;
        }

        .dropdowns select {
            flex: 1;
        }

        textarea {
            width: 100%;
            padding: 10px;
            background-color: #1c1c2e;
            color: #e0e0f1;
            border: 1px solid #3a3a4f;
            border-radius: 4px;
            resize: none;
        }

        textarea:focus {
            outline: none;
            border-color: #79b8ff;
        }

        button {
            padding: 10px 20px;
            background-color: #79b8ff;
            border: none;
            border-radius: 4px;
            color: #1e1e2f;
            font-weight: bold;
            cursor: pointer;
        }

        button:hover {
            background-color: #57a6e3;
        }

        .proxy-input-container {
            display: flex;
            gap: 10px;
        }

        .proxy-input-container input,
        .proxy-input-container textarea {
            flex: 1;
            padding: 10px;
            background-color: #1c1c2e;
            color: #e0e0f1;
            border: 1px solid #3a3a4f;
            border-radius: 4px;
        }

        .proxy-credentials {
            margin-top: 20px;
            display: flex;
            flex-direction: column;
            align-items: center; /* Center the inputs horizontally */
            gap: 1px; /* Space between the inputs */
        }

        .proxy-credentials label,
        .proxy-credentials input {
            width: 95%;
            /* Limit the width of the inputs */
        }

        .proxy-generator {
            display: flex;
            gap: 10px;
        }

        .proxy-generator input[type="number"] {
            flex: 1;
        }

        .proxy-generator button {
            flex: 1;
        }
        .discord-widget {
            flex: 1;
            margin: 40px;
            display: flex;
            justify-content: center;
            align-items: flex-start;
        }

        iframe {
            border: none;
            border-radius: 8px;
            box-shadow: 0 4px 10px rgba(0, 0, 0, 0.6);
        }
    </style>
</head>
<body>
    
    <div class="container">
        <h1>Proxy Setup</h1>
        
        <!-- Connection Type -->
        <div class="section">
            <label>Connection Type:</label>
            <input type="radio" name="connectionType" value="Residential" checked> Residential (NaN Peers Online)
            <input type="radio" name="connectionType" value="Mobile"> Mobile (NaN Peers Online)
        </div>
        
        <!-- Location Settings -->
        <div class="section">
            <label>Location Settings:</label>
            <div class="section">
           <label>Gateway:</label>
           <input type="radio" name="gateway" value="Asia"> Asia
           <input type="radio" name="gateway" value="America"> America
           <input type="radio" name="gateway" value="Europe" checked> Europe
        </div>
        <label>Country:</label>
            <select id="countryDropdown">
                <!-- Countries -->
            </select>
            <div id="locationDropdowns" class="dropdowns" style="display: none;">
                <select id="regionDropdown">
                    <option value="random">Region: Random</option>
                </select>
                <select id="citySelector">
                    <option value="random">City: Random</option>
                </select>
                <select id="ispSelector">
                    <option value="random">ISP: Random</option>
                </select>
            </div>
        </div>

        <!-- Session Type -->
        <div class="section">
            <label>Session Type:</label>
            <input type="radio" name="sessionType" value="Sticky" onchange="updateSessionType()" checked> Sticky
            <div id="sessionStickyOptions">
                <select id="stickyTypeSelector" onchange="updateStickyInput()">
                    <option value="super">Sticky</option>
                    <option value="custom">Custom</option>
                </select>
                <input id="customStickyInput" type="number" placeholder="Enter duration (1-120 minutes)" min="1" max="120" style="display: none;">
            </div>
        </div>

        <!-- Proxy Access -->
        <div class="section">
            <div>
                <label>Protocol:</label>
                <input type="radio" name="protocol" value="HTTP"> HTTP
                <input type="radio" name="protocol" value="SOCKS5" checked> SOCKS5
            </div>
        </div>

        <!-- Proxy Generator -->
        <div class="section">
            <h2>Proxy Generator:</h2>

            <!-- Proxy Username and Access Key -->
            <div class="proxy-credentials">
                <label for="proxyUsername">Proxy Username:</label>
                <input type="text" id="proxyUsername" placeholder="Enter proxy username">
                <label for="proxyAccessKey">Proxy Access Key:</label>
                <input type="password" id="proxyAccessKey" placeholder="Enter proxy access key">
            </div>

            <!-- Save Credentials Checkbox -->
            <div class="section">
                <label for="saveCredentials">
                    <input type="checkbox" id="saveCredentials"> Save proxy username and access key
                </label>
            </div>
            <div class="proxy-input-container">
                <input type="number" id="proxyAmount" placeholder="Number of proxies" style="width: 48%; margin-right: 4%;">
                <button id="generateButton" style="width: 48%; background-color: #79b8ff; border: none; border-radius: 4px; padding: 10px; color: #1e1e2f; font-weight: bold; cursor: pointer;">Generate</button>
            </div>
        </div>
    </div>

    <script>
    
        let regions = {}; 

        document.addEventListener("DOMContentLoaded", function () {
    fetch('https://proxynade.net/countries.php')
        .then(response => {
            if (!response.ok) {
                throw new Error('Network response was not ok');
            }
            return response.json();
        })
        .then(data => {
            console.log('API Response:', data);

            if (data.ret === 0 && data.ret_data) {
                let countries = data.ret_data;

                
                countries.sort((a, b) => a.en_name.localeCompare(b.en_name));

                const countryDropdown = document.getElementById('countryDropdown');

                countries.forEach(country => {
                    const option = document.createElement('option');
                    option.value = country.name; 
                    option.textContent = country.en_name; 
                    countryDropdown.appendChild(option);
                });

                countryDropdown.addEventListener('change', function () {
                    const selectedCountry = countryDropdown.value;

                    if (selectedCountry) {
                        console.log(selectedCountry);
                    }
                });
            } else {
                console.error('Error fetching country data:', data.msg);
            }
        })
        .catch(error => {
            console.error('Error fetching country data:', error);
        });
});
        function generateProxies(count, user, country, protocol, pass, duration,gateway) {
    const randomString = (length) => {
        const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
        let result = '';
        for (let i = 0; i < length; i++) {
            result += characters.charAt(Math.floor(Math.random() * characters.length));
        }
        return result;
    };

    const proxies = [];
    for (let i = 0; i < count; i++) {
        const host = '.proxynade.net';
        const proxyUsername = user || `noproxy4u`;  
        const selectedCountry = country || 'US';  
        const sessionType = 'Sticky';  
        const stickyType = 'Zone';    
        const protocolType = protocol || 'http';  
        const proxyAccessKey = pass || `noproxy4u`;  
        const customDuration = duration || '30m';  

        const proxyLine = `${gateway}${host}:4950:${proxyUsername}-zone-star-region-${selectedCountry}-session-${randomString(8)}-sessTime-${customDuration}:${proxyAccessKey}`;
        proxies.push(proxyLine);
    }

    return proxies;
}

        function updateSessionType() {
            const sessionStickyOptions = document.getElementById('sessionStickyOptions');
            const sessionSticky = document.querySelector('input[name="sessionType"][value="Sticky"]').checked;

            if (sessionSticky) {
                sessionStickyOptions.style.display = 'block';
            } else {
                sessionStickyOptions.style.display = 'none';
            }
        }

        function updateStickyInput() {
            const stickyType = document.getElementById('stickyTypeSelector').value;
            const customStickyInput = document.getElementById('customStickyInput');

            if (stickyType === 'custom') {
                customStickyInput.style.display = 'block';
            } else {
                customStickyInput.style.display = 'none';
            }
        }

        function getCookie(name) {
            const cookieArr = document.cookie.split(';');
            for (let i = 0; i < cookieArr.length; i++) {
                let cookie = cookieArr[i].trim();
                if (cookie.startsWith(name + '=')) {
                    return cookie.substring(name.length + 1);
                }
            }
            return '';
        }

        window.onload = function() {
            const savedUsername = getCookie('proxyUsername');
            const savedAccessKey = getCookie('proxyAccessKey');
            
            if (savedUsername) {
                document.getElementById('proxyUsername').value = savedUsername;
            }
            if (savedAccessKey) {
                document.getElementById('proxyAccessKey').value = savedAccessKey;
            }
        };

        document.getElementById('generateButton').addEventListener('click', function() {
    const proxyAmount = document.getElementById('proxyAmount').value;
    const proxyUsername = document.getElementById('proxyUsername').value;
    const proxyAccessKey = document.getElementById('proxyAccessKey').value;
    const saveCredentials = document.getElementById('saveCredentials').checked;

    let gateway = document.querySelector('input[name="gateway"]:checked').value;
    if (gateway === 'Asia') {
        gateway = 'asia';
    } else if (gateway === 'Europe') {
        gateway = 'europe';
    } else if (gateway === 'America') {
        gateway = 'america';
    }
    
    const countryDropdown = document.getElementById('countryDropdown');
    const selectedCountry = countryDropdown.options[countryDropdown.selectedIndex].value;

    const sessionType = document.querySelector('input[name="sessionType"]:checked').value;

    let stickyType = '';
    let customDuration = 120;  

    if (sessionType === 'Sticky') {
        stickyType = document.getElementById('stickyTypeSelector').value;
        
        if (stickyType === 'custom') {
            customDuration = document.getElementById('customStickyInput').value;
            stickyType = `Custom: ${customDuration} seconds`;  
        } else {
            stickyType = `Default: ${customDuration} seconds`;
        }
    }

    const protocol = document.querySelector('input[name="protocol"]:checked').value;

    if (saveCredentials) {
        document.cookie = `proxyUsername=${proxyUsername};path=/;max-age=77776000`; 
        document.cookie = `proxyAccessKey=${proxyAccessKey};path=/;max-age=77776000`; 
    }

    console.log(`Gateway: ${gateway}`);
    console.log(`Country: ${selectedCountry}`);
    console.log(`Session Type: ${sessionType}`);
    if (sessionType === 'Sticky') {
        console.log(`Sticky Type: ${stickyType}`);
    }
    console.log(`Protocol: ${protocol}`);
    console.log(`Proxy Username: ${proxyUsername}`);
    console.log(`Proxy Access Key: ${proxyAccessKey}`);
    console.log(`Number of Proxies: ${proxyAmount}`);
    console.log(`Custom Duration: ${customDuration}`);

    const generatedProxies = generateProxies(proxyAmount, proxyUsername, selectedCountry, protocol, proxyAccessKey, customDuration, gateway);

    const proxyWindow = window.open('', 'Generated Proxies', 'width=600,height=400');
    proxyWindow.document.write('<html><head><title></title></head><body>');
    proxyWindow.document.write('<h1></h1>');
    proxyWindow.document.write('<ul>');
    proxyWindow.document.write('<pre>');
        generatedProxies.forEach(proxy => {
            proxyWindow.document.write(`${proxy}\n`);
        });

    proxyWindow.document.write('</pre>');
    proxyWindow.document.write('</body></html>');;
    proxyWindow.document.close();
    });


    </script>
</body>
</html>