隣のページにジャンプするUserScript
code:script.js
const project = 'gosyujin';
const defaultSkip = 0;
const defaultSort = 'updated';
const defaultLimit = 100;
const loadTitles = (skip = defaultSkip, sort = defaultSort, limit = defaultLimit) => {
fetch(/api/pages/${project}?skip=${skip}&sort=${sort}&limit=${limit}&q=)
.then(response => {
return response.json()
})
.then(json => {
const currentIndex = json.pages.findIndex(p => p.id === scrapbox.Page.id);
if (json.skip + limit > json.count) throw new Error('隣のページがありませんでした');
if (currentIndex === -1) {
loadTitles(skip + limit, sort, limit);
} else {
location.href = /${project}/${encodeURIComponent(json.pages[currentIndex+1].title)};
}
})
.catch(error => {
console.error(error.message);
});
}
scrapbox.PageMenu.addMenu({
title: '隣のページにジャンプする',
image: 'https://i.gyazo.com/8203e7c0b49934fc8a1d11845e5d28f6/raw',
onClick: () => loadTitles()
});
更新履歴
v0.1.0(2021/12/01)
今のページがなければfetchしていく(2021/12/03)
scrapbox.Project.pagesでもできる…?
隣のページが存在しなかったらエラーにした