Scrapbox-theme-saver
視認性のため、Dark themeは除いている
本体
code:script.js
let presentTheme = document.head.parentElement.dataset.projectTheme ?? 'default-light';
let executed = false;
export function execute({interval}) {
if (executed) return;
executed = true;
setInterval(() => {
presentTheme = getNextTheme();
data-project-themeが存在しない場合もあるので、setAttribute()を使って設定している
code:script.js
document.head.parentElement
.setAttribute("data-project-theme", presentTheme);
},
interval);
const observer = new MutationObserver(() => {
document.head.parentElement.setAttribute("data-project-theme", presentTheme);
});
observer.observe(document.head.getElementsByTagName('title')?.0, {childList: true}); }
Themeの文字列をランダムに返す
常に違うThemeに変わるようにしている
code:script.js
const themeList = [
default-light,
default-minimal,
paper-light,
paper-dark,
blue,
purple,
green,
orange,
red,
hacker1,
hacker2,
winter,
spring,
summer,
automn,
tropical,
kyoto,
newyork,
paris,
mred,
lgreen,
];
function getNextTheme() {
return theme === document.head.parentElement.dataset.projectTheme ?
getNextTheme() :
theme;
}
乱数生成用関数
code:script.js
function getRandomInt(min, max) {
min = Math.ceil(min);
max = Math.floor(max);
return Math.floor(Math.random() * (max - min) + min);
}