scrapbox-lazy-watch
通知は各自が作るべきではないかをScrapboxに実装してみる。
lazyなエゴサーチ機能を目指す。
2022/1/10
エゴサーチという表現が的確とは言えないな。
既存の言葉では表現が難しい。
2022/1/12
通知の条件をユーザーに調整してもらうと、パラメーター弄りをし始めてしまう。
一方で、watchTargetsが自分の興味関心を表していて、自己紹介にはなるかもしれない。
次回作 zeroconf-watch
index.jsexport const runScrapboxLazyWatch = async ({ watchTargets }) => { const nowUNIXTime = Math.floor(new Date().getTime() / 1000); const projectName = scrapbox.Project.name;
const checkedKey = `scrapbox-lazy-watch-checked-${projectName}`; const checkedUNIXTime = Number( localStorage.getItem(checkedKey) ?? String(nowUNIXTime) ); localStorage.setItem(checkedKey, String(nowUNIXTime));
const streamResponse = await fetch(`/api/stream/${projectName}`); const stream = await streamResponse.json();
const userResponse = await fetch("/api/users/me"); const user = await userResponse.json();
[ ...new Set( watchTargets.flatMap((watchTarget) => stream.pages.flatMap((page) => page.lines.flatMap((line) => checkedUNIXTime < line.updated && line.userId !== user.id && line.text.includes(watchTarget) ? [`/${projectName}/${encodeURIComponent(page.title)}#${line.id}`] : [] ) ) ) ), ].forEach((url) => open(url));};