import { useState, useEffect } from "preact/hooks"; import { useTranslation } from "react-i18next"; import { ToastContainer, toast } from "react-toastify"; interface WispInputProps { placeholder: string; } function WispInput(props: WispInputProps) { const { t } = useTranslation(); const value = localStorage.getItem("wispUrl") || (location.protocol === "https:" ? "wss://" : "ws://") + location.host + "/wisp/"; const [inputValue, setInputValue] = useState(value); function validateUrl(url: string) { let finalUrl = url; if (finalUrl.startsWith("http://")) { finalUrl = finalUrl.replace("http://", "ws://"); } else if (finalUrl.startsWith("https://")) { finalUrl = finalUrl.replace("https://", "wss://"); } } function handleChange() { const url = validateUrl((document.getElementById("input") as HTMLInputElement).value); localStorage.setItem("wispUrl", url); } return (