ColoringSameTagAsTitle
#userscript
同名タイトルのハッシュタグの強調
日記(単語)におけるタスク管理に使用
code:ColoringSameTagAsTitle.js
// sametag.js の中身
const initSameTag = () => {
if (!window.scrapbox) return; // まだ準備ができていなければ何もしない
const highlightSelfTag = () => {
const pageTitle = scrapbox.Page.title; // Scrapbox は小文字が一般的です
if (!pageTitle) return;
const hashTags = document.querySelectorAll('.line atype="hashTag"');
hashTags.forEach(tag => {
const tagText = tag.textContent.substring(1);
if (tagText === pageTitle) {
tag.style.backgroundColor = '#ffefef';
tag.style.borderColor = '#ffb3b3';
tag.style.color = '#d00000';
} else {
tag.style.backgroundColor = '';
tag.style.borderColor = '';
tag.style.color = '';
}
});
};
const observer = new MutationObserver(highlightSelfTag);
observer.observe(document.querySelector('.app'), { childList: true, subtree: true });
highlightSelfTag();
};
// Scrapboxの準備ができるまで待つ
if (window.scrapbox) {
initSameTag();
} else {
// まだなら少し待って再試行
const checkTimer = setInterval(() => {
if (window.scrapbox) {
clearInterval(checkTimer);
initSameTag();
}
}, 100);
}