アイコンフィルターが有効なランダムジャンプボタン
生のJavaScriptを手書きとか1年ぶりぐらいじゃないだろうか
方針
1. ランダムジャンプボタンを押しまくって自分のアイコンがあるページが開いたら停止
ロジックはscrapbox.Page.lines.some(e => e.text.includes("[wogikaze.icon]"))
2. アイコンフィルターを有効にしたページリストから飛ぶ
できたwogikaze.icon
すごい!zatto.icon
code:1.js
scrapbox.PageMenu.addMenu({
title: 'Jump to an page has user icon',
onClick: () => {
const lines = document.getElementsByClassName('lines')?.0; const observer = new MutationObserver(() => {
if (scrapbox.Page.lines.some(e => e.text.includes([${scrapbox.User.name}.icon]))) {
console.log(/${scrapbox.Project.name}/${scrapbox.Page.title} has user icon.);
observer.disconnect();
return;
}
document.getElementsByClassName('random-jump-button')?.0.click(); });
observer.observe(lines, {childList: true});
document.getElementsByClassName('random-jump-button')?.0.click(); },
});
う、動いたwogikaze.icon
code:2.js
scrapbox.PageMenu.addMenu({
title: 'Jump to an page has user icon',
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 hasIcon = false;
let count = 0;
while (!hasIcon) {
const nextPage = await getNextPage();
console.log(${++count}: /${project}/${nextPage.title});
let hasIcon = nextPage.lines.some(e => e.text.includes([${scrapbox.User.name}.icon]));
if (hasIcon) { location.href = /${project}/${encodeURIComponent(nextPage.title)}; }
}
},
});