未読のページにランダムジャンプするUserScript:ページを開かずに未読を判定するver
ページを開かずに未読を判定するver
script.jsscrapbox.PageMenu.addMenu({
title: 'Jump to an unread page',
image: 'https://img.icons8.com/ios/180/shuffle.png',
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 title = pages[Math.floor(Math.random() * pages.length)].title;
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)}`; }
}
},
});