/// /// /// import { useStatusBar, makeSocket, deletePage, disconnect, Socket, } from "../scrapbox-userscript-std/mod.ts"; import { delay } from "../deno_std%2Fasync/mod.ts"; export interface Page { project: string; title: string; } export const deletePages = async (pages: Page[]): Promise => { const { render, dispose } = useStatusBar(); let socket: Socket | undefined; try { socket = await makeSocket(); let counter = 0; for (const page of pages) { await deletePage(page.project, page.title, { socket }); counter++; render( { type: "spinner" }, { type: "text", text: `delete ${counter}/${pages.length} pages...`}, ); } render( { type: "check-circle" }, { type: "text", text: `deleted ${pages.length} pages.`}, ); } catch(e: unknown) { render( { type: "exclamation-triangle" }, { type: "text", text: e instanceof Error ? `${e.name} ${e.message}` : `Unknown error! (see developper console)`, }, ); console.error(e); } finally { if (socket) await disconnect(socket); await delay(1000); dispose(); } }