1
0
mirror of https://github.com/kognise/water.css.git synced 2025-02-23 21:35:42 +01:00
css-water.css/script.js

46 lines
1.4 KiB
JavaScript
Raw Normal View History

2019-05-29 15:40:45 +09:00
(function () {
const switchBtn = document.getElementById('switch');
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;
}
})
})();