2019-05-29 15:40:45 +09:00
|
|
|
(function () {
|
|
|
|
const switchBtn = document.getElementById('switch');
|
2019-05-03 01:21:48 +00:00
|
|
|
const stylesheet = document.getElementById('stylesheet');
|
2019-05-29 18:56:36 +09:00
|
|
|
const darkMql = matchMedia('(prefers-color-scheme: dark)');
|
|
|
|
const lightMql = matchMedia('(prefers-color-scheme: light)');
|
2019-05-29 15:40:45 +09:00
|
|
|
const themes = {
|
|
|
|
dark: '../dist/dark.css',
|
|
|
|
darkStandalone: '../dist/dark.standalone.css',
|
|
|
|
light: '../dist/light.css',
|
|
|
|
lightStandalone: '../dist/light.standalone.css'
|
|
|
|
};
|
|
|
|
|
|
|
|
switchBtn.addEventListener('click', function() {
|
2019-05-29 18:56:36 +09:00
|
|
|
const readTheme = stylesheet.getAttribute('href');
|
|
|
|
if (readTheme === themes.dark) {
|
|
|
|
if (darkMql.matches) {
|
|
|
|
stylesheet.href = themes.lightStandalone
|
|
|
|
} else if (lightMql.matches) {
|
|
|
|
stylesheet.href = themes.darkStandalone
|
|
|
|
} else {
|
|
|
|
stylesheet.href = themes.light
|
|
|
|
}
|
|
|
|
} else if (readTheme === themes.darkStandalone) {
|
|
|
|
stylesheet.href = themes.lightStandalone
|
|
|
|
} else if (readTheme === themes.light) {
|
|
|
|
if (darkMql.matches) {
|
|
|
|
stylesheet.href = themes.lightStandalone
|
|
|
|
} else if (lightMql.matches) {
|
|
|
|
stylesheet.href = themes.darkStandalone
|
|
|
|
} else {
|
|
|
|
stylesheet.href = themes.dark
|
|
|
|
}
|
|
|
|
} else if (readTheme === themes.lightStandalone) {
|
|
|
|
stylesheet.href = themes.darkStandalone
|
2019-05-29 15:40:45 +09:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2019-05-29 18:56:36 +09:00
|
|
|
darkMql.addListener(function (mql) {
|
2019-05-29 15:40:45 +09:00
|
|
|
if (mql.matches) {
|
|
|
|
stylesheet.href = themes.dark;
|
|
|
|
} else {
|
|
|
|
stylesheet.href = themes.light;
|
|
|
|
}
|
|
|
|
})
|
|
|
|
})();
|