<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>RHIZ PROXY LIST</title>
    <style>
        @keyframes fadeIn {
            from { opacity: 0; transform: translateY(20px); }
            to { opacity: 1; transform: translateY(0); }
        }

        @keyframes pulse {
            0% { transform: scale(1); }
            50% { transform: scale(1.05); }
            100% { transform: scale(1); }
        }

        body {
            font-family: 'Arial', sans-serif;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            margin: 0;
            padding: 20px;
            display: flex;
            justify-content: center;
            align-items: center;
            min-height: 100vh;
        }

        .container {
            background-color: rgba(255,255,255,0.9);
            border-radius: 15px;
            box-shadow: 0 15px 25px rgba(0,0,0,0.1);
            width: 100%;
            max-width: 800px;
            padding: 30px;
            animation: fadeIn 0.7s ease-out;
        }

        h1 {
            text-align: center;
            color: #333;
            margin-bottom: 20px;
            background: linear-gradient(to right, #667eea, #764ba2);
            -webkit-background-clip: text;
            -webkit-text-fill-color: transparent;
        }

        #proxyTable {
            width: 100%;
            border-collapse: separate;
            border-spacing: 0 10px;
        }

        #proxyTable tr {
            transition: all 0.3s ease;
            opacity: 0;
            animation: fadeIn 0.5s forwards;
            animation-delay: calc(var(--delay) * 0.1s);
        }

        #proxyTable tr:hover {
            transform: scale(1.02);
            box-shadow: 0 5px 15px rgba(0,0,0,0.1);
        }

        #proxyTable th, #proxyTable td {
            padding: 15px;
            text-align: left;
            background-color: white;
        }

        #proxyTable th {
            background-color: #667eea;
            color: white;
        }

        .copy-btn {
            background-color: #764ba2;
            color: white;
            border: none;
            padding: 8px 15px;
            cursor: pointer;
            border-radius: 20px;
            transition: all 0.3s ease;
        }

        .copy-btn:hover {
            animation: pulse 0.5s;
            background-color: #667eea;
        }

        #loadingIndicator {
            text-align: center;
            color: white;
            font-size: 18px;
            margin-top: 20px;
        }

        .action-buttons {
            margin-top: 20px;
            text-align: center;
        }

        .action-buttons button {
            background-color: #667eea;
            color: white;
            border: none;
            padding: 10px 20px;
            cursor: pointer;
            border-radius: 20px;
            margin: 0 10px;
            transition: background-color 0.3s;
        }

        .action-buttons button:hover {
            background-color: #764ba2;
        }
    </style>
</head>
<body>
    <div class="container">
        <h1>RHIZ PROXY LIST</h1>
        <div class="action-buttons">
            <button id="refreshButton" onclick="refreshProxies()">Refresh</button>
            <button onclick="downloadProxies()">Download</button>
        </div>
        <div id="loadingIndicator">Loading proxies...</div>
        <table id="proxyTable" style="display:none;">
            <thead>
                <tr>
                    <th>IP Address</th>
                    <th>Port</th>
                    <th>Country</th>
                    <th>Type</th>
                    <th>Action</th>
                </tr>
            </thead>
            <tbody id="proxyList">
                <!-- Proxy entries will be added dynamically -->
            </tbody>
        </table>
    </div>

    <script>
        let proxies = [];
        let refreshCooldown = false;

        async function fetchProxies() {
            try {
                const proxyTypes = ['http', 'https', 'socks4', 'socks5'];
                proxies = [];

                for (const type of proxyTypes) {
                    const response = await fetch(`https://api.proxyscrape.com/v2/?request=getproxies&protocol=${type}&timeout=10000&country=all&simplified=true`);
                    const proxyText = await response.text();
                    const proxyLines = proxyText.trim().split('\n');
                    proxyLines.forEach(line => {
                        const [ip, port] = line.split(':');
                        if (ip && port) {
                            proxies.push({
                                ip: ip,
                                port: port,
                                country: 'Mixed',
                                type: type.toUpperCase()
                            });
                        }
                    });
                }

                renderProxyList(proxies);
            } catch (error) {
                console.error('Error fetching proxies:', error);
                document.getElementById('loadingIndicator').textContent = 'Failed to load proxies. Please try again.';
            }
        }

        function renderProxyList(proxyData) {
            const proxyList = document.getElementById('proxyList');
            const loadingIndicator = document.getElementById('loadingIndicator');
            const proxyTable = document.getElementById('proxyTable');

            proxyList.innerHTML = '';
            loadingIndicator.style.display = 'none';
            proxyTable.style.display = 'table';

            proxyData.forEach((proxy, index) => {
                const row = document.createElement('tr');
                row.style.setProperty('--delay', index);
                row.innerHTML = `
                    <td>${proxy.ip}</td>
                    <td>${proxy.port}</td>
                    <td>${proxy.country}</td>
                    <td>${proxy.type}</td>
                    <td>
                        <button class="copy-btn" onclick="copyProxy('${proxy.ip}:${proxy.port}')">Copy</button>
                    </td>
                `;
                proxyList.appendChild(row);
            });
        }

        function copyProxy(proxyAddress) {
            navigator.clipboard.writeText(proxyAddress).then(() => {
                alert(`Copied proxy: ${proxyAddress}`);
            });
        }

        function downloadProxies() {
            const blob = new Blob([proxies.map(proxy => `${proxy.ip}:${proxy.port}`).join('\n')], { type: 'text/plain' });
            const link = document.createElement('a');
            link.href = URL.createObjectURL(blob);
            link.download = 'proxies.txt';
            link.click();
        }

        function refreshProxies() {
            if (refreshCooldown) {
                alert("Please wait 30 seconds before refreshing again.");
                return;
            }

            fetchProxies();
            document.getElementById('refreshButton').disabled = true;
            refreshCooldown = true;
            setTimeout(() => {
                document.getElementById('refreshButton').disabled = false;
                refreshCooldown = false;
            }, 30000); // 30 seconds cooldown
        }

        // Fetch proxies when page loads
        fetchProxies();
    </script>
</body>
</html>