scrapbox-userscript-std/browser/websocketの動作確認用コード
テスト方法
1. テストしたいcommitのコードをbundleして../scrapbox-userscript-std/mod.jsに貼り付ける
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 ? [
"新しい行その1",
] : [
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");