scrapbox-theme-customizer
使い方
jsimport {setTheme} from '/api/code/takker/scrapbox-theme-customizer/script.js';
setTheme('papar-dark-dark');
本体
script.jsimport {themes} from '../ScrapboxのTheme/script.js';
let executed = false;
export function setTheme(theme) {
if (executed) return;
executed = true;
if (!themes.includes(theme)) throw Error(`"${theme}" is an invalid theme name.`);
data-project-theme
が存在しない場合もあるので、 setAttribute()
を使って設定している
script.js // 初期化
document.documentElement.setAttribute("data-project-theme", theme);
// ページ更新用
const observer = new MutationObserver(() => {
document.documentElement.setAttribute("data-project-theme", theme);
});
observer.observe(document.head.getElementsByTagName('title')?.[0], {childList: true});
}