import { useStatusBar } from "../scrapbox-userscript-std/dom.ts"; import { KeyWatcher } from "../KeyWatcher/mod.ts"; const { render, dispose } = useStatusBar(); let animationId: number | undefined; const update = (text: string) => { if(animationId !== undefined) cancelAnimationFrame(animationId); animationId = requestAnimationFrame(() => render( { type: "text", text, } )); } const keyWatcher = new KeyWatcher() try{ let timer: number | undefined; for await(const sequence of keyWatcher.listen()) { clearTimeout(timer); if (sequence.endsWith("")) break; update(sequence); timer = setTimeout(() => { keyWatcher.reset(); update(""); }, 3000); } } catch (e) { console.error(e); } finally { dispose(); }