<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Free Proxy List By RhizExploit</title>
    <style>
        /* General body styling */
        body {
            font-family: Arial, sans-serif;
            margin: 0;
            padding: 0;
            background: linear-gradient(to right, #0066cc, #3399ff);
            color: #333;
            display: flex;
            justify-content: center;
            align-items: center;
            min-height: 100vh;
        }
        
        /* Container styling */
        .container {
            max-width: 800px;
            background: #fff;
            padding: 20px;
            border-radius: 10px;
            box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
            text-align: center;
        }

        /* Header styling */
        h1 {
            color: #007bff;
            font-size: 24px;
            margin-bottom: 20px;
        }

        /* Select and Button styling */
        select, button {
            padding: 10px;
            margin: 10px 5px;
            font-size: 16px;
            border: 1px solid #007bff;
            border-radius: 5px;
            outline: none;
        }

        button {
            background-color: #007bff;
            color: white;
            cursor: pointer;
            transition: background 0.3s ease;
        }
        
        button:hover {
            background-color: #0056b3;
        }

        /* Notification styling */
        #notification {
            color: #d9534f;
            margin-top: 10px;
            font-size: 16px;
            font-weight: bold;
        }

        /* Table styling */
        table {
            width: 100%;
            border-collapse: collapse;
            margin-top: 20px;
        }

        th, td {
            padding: 12px;
            border: 1px solid #ddd;
            text-align: center;
        }

        th {
            background-color: #007bff;
            color: #fff;
        }

        /* Row hover effect */
        tr:hover {
            background-color: #f1f1f1;
        }

        /* Responsive styling */
        @media (max-width: 600px) {
            h1 {
                font-size: 20px;
            }
            select, button {
                width: 100%;
                margin: 10px 0;
            }
        }
    </style>
</head>
<body>
    <div class="container">
        <h1>Free Proxy List By RhizExploit</h1>
        <p>Choose proxy type:</p>
        <select id="proxyType">
            <option value="http">HTTP</option>
            <option value="socks4">SOCKS4</option>
            <option value="socks5">SOCKS5</option>
        </select>
        <button id="refreshButton" onclick="handleRefresh()">Refresh Proxy List</button>
        <button onclick="downloadProxyList('txt')">Download as TXT</button>
        <button onclick="downloadProxyList('json')">Download as JSON</button>
        <p id="notification"></p>
        <table>
            <thead>
                <tr>
                    <th>IP Address</th>
                    <th>Port</th>
                    <th>Country</th>
                    <th>Type</th>
                </tr>
            </thead>
            <tbody id="proxyTable">
                <!-- Proxy list will be populated here -->
            </tbody>
        </table>
    </div>

    <script>
        const delayTime = 20000; // Delay time in milliseconds (3 seconds)
        let currentProxyList = []; // Store the fetched proxy list

        function handleRefresh() {
            const refreshButton = document.getElementById('refreshButton');
            const notification = document.getElementById('notification');
            let remainingTime = delayTime / 1000; // Convert to seconds

            refreshButton.disabled = true; // Disable button
            notification.textContent = `Please wait... refreshing proxy list in ${remainingTime} seconds.`;

            // Update countdown every second
            const countdownInterval = setInterval(() => {
                remainingTime--;
                notification.textContent = `Please wait... refreshing proxy list in ${remainingTime} seconds.`;
                if (remainingTime <= 0) {
                    clearInterval(countdownInterval); // Clear interval when countdown finishes
                }
            }, 1000);

            // Fetch proxies and re-enable button after delay
            fetchProxies();

            setTimeout(() => {
                refreshButton.disabled = false;
                notification.textContent = ''; // Clear the notification message
            }, delayTime);
        }

        async function fetchProxies() {
            const proxyType = document.getElementById('proxyType').value;
            const apiUrl = `https://api.proxyscrape.com/?request=displayproxies&protocol=${proxyType}`;

            try {
                const response = await fetch(apiUrl);
                const proxies = await response.text();
                const proxyArray = proxies.split('\n').filter(Boolean); // Filter out empty entries

                currentProxyList = []; // Reset the proxy list
                const proxyTable = document.getElementById('proxyTable');
                proxyTable.innerHTML = ''; // Clear existing rows

                for (const proxy of proxyArray) {
                    const [ip, port] = proxy.split(':');
                    const country = await fetchCountry(ip);
                    
                    const row = document.createElement('tr');
                    row.innerHTML = `
                        <td>${ip}</td>
                        <td>${port}</td>
                        <td>${country}</td>
                        <td>${proxyType.toUpperCase()}</td>
                    `;
                    proxyTable.appendChild(row);

                    // Add to current proxy list
                    currentProxyList.push({ ip, port, country, type: proxyType.toUpperCase() });
                }
            } catch (error) {
                console.error('Error fetching proxies:', error);
            }
        }

        async function fetchCountry(ip) {
            try {
                const response = await fetch(`http://ip-api.com/json/${ip}`);
                const data = await response.json();
                return data.country || 'Unknown';
            } catch (error) {
                console.error('Error fetching country:', error);
                return 'Unknown';
            }
        }

        function downloadProxyList(format) {
            let dataStr;
            if (format === 'txt') {
                dataStr = currentProxyList.map(proxy => `${proxy.ip}:${proxy.port}`).join('\n');
                const blob = new Blob([dataStr], { type: 'text/plain' });
                const url = URL.createObjectURL(blob);
                const a = document.createElement('a');
                a.href = url;
                a.download = 'proxy_list.txt';
                a.click();
                URL.revokeObjectURL(url);
            } else if (format === 'json') {
                dataStr = JSON.stringify(currentProxyList, null, 2);
                const blob = new Blob([dataStr], { type: 'application/json' });
                const url = URL.createObjectURL(blob);
                const a = document.createElement('a');
                a.href = url;
                a.download = 'proxy_list.json';
                a.click();
                URL.revokeObjectURL(url);
            }
        }

        // Initial fetch of HTTP proxies on page load
        fetchProxies();
    </script>
</body>
</html>