マルチプロジェクト版ランダムジャンプ
#UserScript
参考
/villagepump/マルチプロジェクト版ランダムジャンプUserScript
todo
画像が適当
微妙に重い
tableに2カラム目がないと発火されない
マルチプロジェクト版ランダムジャンプ#609bd8ae19827000001215acこの辺の処理が雑いから?
いやあっても無理なやつ無理だな
1度に1個しか開けないのでもう少し開きたい
code:script.js
(function () {
const tables = [
'https://scrapbox.io/api/table/mrsekut-b/いくつかのスクボからページをランダムに表示する/projects.csv'
];
const randomChoiceFrom = arr => {
const idx = Math.floor(Math.random() * arr.length);
return arridx;
};
scrapbox.PageMenu.addMenu({
title: 'ランダムジャンプ',
image: 'https://dummyimage.com/200x200/ffffff/8f088f&text=ランダム',
onClick: async () => {
new Promise((resolve, reject) => {
fetch(randomChoiceFrom(tables))
.then(res => res.text())
.then(resolve)
.catch(reject);
}).then(text => {
const projects = text
.split('\n')
.map(line => line.split(',')0.replace(/\|\/g, ''));
const project = randomChoiceFrom(projects);
const limit = 100;
const skip = 0;
fetch(/api/pages${project}?limit=${limit}&skip=${skip})
.then(res => res.json())
.then(({ pages }) => {
const titles = pages.map(p => p.title);
const title = randomChoiceFrom(titles);
window.open(https://scrapbox.io${project}/${title});
})
.catch(err => {
console.error('fetch failed', err);
});
});
}
});
})();