未読のページにランダムジャンプするUserScript:ページを開かずに未読を判定するver
ページを開かずに未読を判定するver
code:script.js
scrapbox.PageMenu.addMenu({
title: 'Jump to an unread page',
onClick: async () => {
const project = scrapbox.Project.name;
const pages = scrapbox.Project.pages.filter(
page => page.exists && page.title !== scrapbox.Page.title
);
const getNextPage = async () => {
const nextPage = await fetch(/api/pages/${project}/${encodeURIComponent(title)});
return await nextPage.json();
}
let isUnread = false;
let count = 0;
while (!isUnread) {
const nextPage = await getNextPage();
console.log(${++count}: /${project}/${nextPage.title});
let isUnread = nextPage.lines.some(line => nextPage.lastAccessed < line.updated);
if (isUnread) { location.href = /${project}/${encodeURIComponent(nextPage.title)}; }
}
},
});