/// /// /// import type { Socket, Manager, ManagerOptions, SocketOptions, } from "https://cdn.esm.sh/v54/socket.io-client@4.2.0/build/index.d.ts"; export type { Socket, Manager, ManagerOptions, SocketOptions }; declare function io(uri: string, opts?: Partial): Socket; const version = "4.2.0"; export async function socketIO(): Promise { const io = await importSocketIO(); return io("https://scrapbox.io", {reconnectionDelay: 5000, transports: ["websocket"]}); } function importSocketIO(): Promise { const url = `https://cdnjs.cloudflare.com/ajax/libs/socket.io/${version}/socket.io.min.js`; if (document.querySelector(`script[src="${url}"]`)) { return Promise.resolve(io); } const script = document.createElement("script"); script.src = url; return new Promise((resolve, reject) => { script.onload = () => resolve(io); script.onerror = (e) => reject(e); document.head.append(script); }); }