scrapbox-userscript-std/browser/websocketの動作確認用コード
scrapbox-userscript-std/browser/websocketのテスト用コード
✅scrapbox-headless-scriptをscrapbox-userscript-stdに統合で使ったやつを移してきた
テスト方法
1. テストしたいcommitのコードをbundleして../scrapbox-userscript-std/mod.jsに貼り付ける
2. 以下のsnippetを@takker/ScrapJupyterで実行する
shortcuts.ts
patch()
新しいページを作るだけ
code:js
import { patch } from "../scrapbox-userscript-std/mod.js";
//新しいページを作るだけ
await patch(scrapbox.Project.name, "test-new-page", (lines) => lines.map(line => line.text));
タイトルのすぐ下に追記する
code:js
import { patch } from "../scrapbox-userscript-std/mod.js";
await patch(scrapbox.Project.name, "test-new-page", (lines) => lines.length < 2 ? [
lines0.text,
"新しい行その1",
] : [
lines0.text,
lines1.text.replace(/(\d+)/, (_, n) => ${parseInt(n) + 1}),
...lines.slice(1).map(line => line.text),
]);
連続実行するとこんな感じになる
https://gyazo.com/04876da91ed4a1513ec2f39f18521b5d
リンクを貼る
code:js
import { patch } from "../scrapbox-userscript-std/mod.js";
//新しいページを作るだけ
await patch(scrapbox.Project.name, "test-new-page", (lines) => [
...lines.map(line => line.text),
" これはたぶん存在しないリンクだと思う",
]);
deletePage()
新しいページを作って消す
code:js
import { patch, deletePage } from "../scrapbox-userscript-std/mod.js";
//新しいページを作って消す
const page = "test-new-page";
await patch(scrapbox.Project.name, page, (lines) => lines.map(line => line.text));
await deletePage(scrapbox.Project.name, page);
pin()
ページが存在しないときはピンしない
code:js
import { pin } from "../scrapbox-userscript-std/mod.js";
await pin(scrapbox.Project.name, "test-new-page");
ページが存在しないときはページを作ってからピンする
code:js
import { pin } from "../scrapbox-userscript-std/mod.js";
await pin(scrapbox.Project.name, "test-new-page", { create: true });
unpin()
ページが存在しなければ何もしない
code:js
import { unpin } from "../scrapbox-userscript-std/mod.js";
await unpin(scrapbox.Project.name, "test-new-page");
#2022-02-11 17:28:14