特定の文字が含まれているページリストにstyleを適用するUserScript
code:script.js
(() => {
// ページの最初の文字が「👉」または「候補」の場合、グレーアウトする
function grayOut(node) {
if (node === null) return;
if (node.querySelector('.description .line span')) {
if (node.querySelector('.description .line span').innerText === '👉') {
node.style = 'opacity: .5;';
}
}
if (node.querySelector('.description .line')) {
if (node.querySelector('.description .line').innerText === '候補') {
node.style = 'opacity: .5;';
}
}
}
// ページリストを監視して、リスト継ぎ足し時はこちらで1件ずつ見る
const targetNode = document.querySelector('.page-list');
const config = { attributes: false, childList: true, subtree: true };
const callback = function(mutationsList, observer) {
for (const mutation of mutationsList) {
if (mutation.type === 'childList') {
if (mutation.addedNodes && mutation.addedNodes.length >= 1) {
console.debug(mutation.addedNodes);
grayOut(mutation.addedNodes0);
}
};
}
};
const observer = new MutationObserver(callback);
observer.observe(targetNode, config);
if (scrapbox.Project.name !== 'gosyujin') return;
// ページ切り替え後はこちらが呼び出される
getPageList();
scrapbox.on('page:changed', getPageList);
function getPageList() {
Array.from(document.querySelectorAll('li.page-list-item')).map(m => grayOut(m));
}
})();
プロジェクトホームのページリストの中に「👉」が入っているカードだけ表示を変えたい
ページのタイトルだとdata-page-titleからcssで判別することができる
settings#62a2a005f4582000009198b0
ページの内容はcssでは引っかけられないのでjs(UserScript)でなんとか
このあたりのタイミングでも実行したい
関連ページの展開 ... を押した時
こっちはまだ
プロジェクトトップページのスクロール
code:ㅤ
Request URL: https://scrapbox.io/api/pages/gosyujin?skip=300&sort=updated&limit=100&q=&field=lines
Request method: GET
Status code: 304 Not Modified`
MutationObserverならページ継ぎ足しの検知もできるみたい
スタイルをむりやり適用できるようにしてみた(2023/02/16)
更新履歴
できるかどうかの検証、とりあえずベタ書き(2023/02/16)
「候補」もグレーアウトするようにした