import { useStatusBar } from "../scrapbox-userscript-std/mod.ts"; import { replace, getLinks } from "./mod.ts"; import { waitForConvertOrder } from "./converter.ts"; export { getLinks }; export const handleReplace = async (text: string, projects: string[]): Promise => { const links = getLinks(text); const result = await waitForConvertOrder([...new Set(links)]); if (!result.convert || result.links.length === 0) return; const bars = new Map(result.links.map((link) => [link.before, useStatusBar()])); await replace(result.links, projects, (status) => { const { link, projectCount, replaced, done } = status; const bar = bars.get(link.before); if (!bar) return; if (done) { bar.render( { type: "check-circle"}, { type: "text", text: `"${link.after}", ${replaced}l. ${projectCount}p.` }, ); setTimeout(() => bar.dispose(), 1000); return; } bar.render( { type: "spinner"}, { type: "text", text: `"${link.after}", ${replaced}l. ${projectCount}p.` }, ); }); };