Skip to content

Never stop coding. Free MIT AI gateway: one endpoint, 375 providers (150+ free), 1,400+ models Kimi, Claude, GPT, Gemini, GLM, DeepSeek, MiniMax. Works with Claude Code, Codex, Cursor, OpenCode, Cline & Copilot. Quota-aware auto-fallback, RTK+Caveman compression saves 15-95% tokens, MCP/A2A, Desktop/PWA. Built by 900+ contributors

1.2 KB
Raw Blame
(function () {
  const input = document.getElementById("url-input");
  const errorEl = document.getElementById("error");
  const saveBtn = document.getElementById("save-btn");
  const cancelBtn = document.getElementById("cancel-btn");

  function isValidOrEmpty(value) {
    const trimmed = value.trim();
    if (!trimmed) return true; // empty = disconnect, handled by main process
    try {
      const parsed = new URL(trimmed);
      return parsed.protocol === "http:" || parsed.protocol === "https:";
    } catch {
      return false;
    }
  }

  window.remoteServerPrompt.getInitialUrl().then((url) => {
    input.value = url || "";
    input.focus();
  });

  saveBtn.addEventListener("click", () => {
    const value = input.value.trim();
    if (!isValidOrEmpty(value)) {
      errorEl.textContent = "Enter a valid http:// or https:// URL, or leave blank to disconnect.";
      return;
    }
    window.remoteServerPrompt.submit(value);
  });

  cancelBtn.addEventListener("click", () => {
    window.remoteServerPrompt.cancel();
  });

  input.addEventListener("keydown", (event) => {
    if (event.key === "Enter") saveBtn.click();
    if (event.key === "Escape") cancelBtn.click();
  });
})();