const toast = (typeof window !== "undefined" && window.createToast) || (typeof window !== "undefined" && window.showToast) || null; const tableBody = document.getElementById("proxyTableBody"); const addProxyBtn = document.getElementById("addProxyBtn"); const addProxyModal = document.getElementById("addProxyModal"); const modalClientSelect = document.getElementById("modalClientSelect"); const modalPortInput = document.getElementById("modalPortInput"); const modalCancelBtn = document.getElementById("modalCancelBtn"); const modalAddBtn = document.getElementById("modalAddBtn"); let pollingInterval = null; // Check if a clientId was provided via URL params (from context menu) const urlParams = new URLSearchParams(window.location.search); const preselectedClientId = urlParams.get("clientId") || ""; // ── Data fetching ───────────────────────────────────────────────────────────── async function fetchProxies() { try { const res = await fetch("/api/proxy/list"); if (!res.ok) return []; const data = await res.json(); return data.proxies || []; } catch { return []; } } async function fetchClients() { try { const res = await fetch("/api/clients?page=1&pageSize=500"); if (!res.ok) return []; const data = await res.json(); return (data.items || []).filter((c) => c.online); } catch { return []; } } // ── Rendering ───────────────────────────────────────────────────────────────── function formatTime(ts) { if (!ts) return "-"; const d = new Date(ts); return d.toLocaleString(); } function renderTable(proxies) { if (!proxies.length) { tableBody.innerHTML = `
No active proxies
Click "Add Proxy" to start routing traffic through a client.
socks5://<server>:${p.port}