scrapbox-theme-customizer
使い方
code:js
import {setTheme} from '/api/code/takker/scrapbox-theme-customizer/script.js';
setTheme('papar-dark-dark');
本体
code:script.js
import {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()を使って設定している
code: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}); }