generated at
Inboxに素早く投入するPage Menu A
Inboxに素早く投入するPage Menu A
おためし実装
ちゃんと動いたっぽい
script.ts
import { addToInbox } from "./mod.ts"; import type { Scrapbox } from "https://raw.githubusercontent.com/scrapbox-jp/types/0.0.8/mod.ts"; declare const scrapbox: Scrapbox; const project = "takker-memex"; const title = "メモ帳"; scrapbox.PageMenu.addMenu({ title: "Add to inbox", image: "/assets/img/logo.svg", onClick: async () => { const item = window.prompt("Type item you wanna add to the inbox"); if (!item || item.trim() === "") return; await addToInbox(project, title, item.split(/\s+/)); }, });

もしうまく記入できなければ、:projectname/:pagetitle?body=:textを使った書き込みにfallbackする
mod.ts
import { patch, useStatusBar, openInTheSameTab, } from "../scrapbox-userscript-std/mod.ts"; import { delay as sleep } from "../deno_std%2Fasync/mod.ts"; export async function addToInbox( project: string, title: string, items: string[] ): Promise<void> { const { render, dispose } = useStatusBar(); try { render( { type: "spinner" }, { type: "text", text: `Adding ${items.length} items...` }, ); await patch(project, title, (lines) => [ ...lines.map((line) => line.text), ...items, ]); render( { type: "check-circle" }, { type: "text", text: "Added to the inbox." }, ); } catch(e: unknown) { render( { type: "exclamation-triangle" }, { type: "text", text: "Failed to add (see console). Write directory instead." }, ); console.error(e); openInTheSameTab(project, title, items.join("\n")); } finally { await sleep(1000); dispose(); } }

#2022-02-21 18:41:11
#2022-02-14 07:04:00