This repository has been archived on 2024-07-22. You can view files and clone it, but cannot push or open issues or pull requests.
Zaimki/plugins/dark.js

30 lines
833 B
JavaScript

export default {
methods: {
detectDark() {
if (!process.client) {
return false;
}
if (localStorage.getItem('darkMode') !== null && localStorage.getItem('darkMode') === 'dark') {
return true;
}
const mediaMatch = window.matchMedia('(prefers-color-scheme: dark)');
return mediaMatch.matches;
},
setMode(dark) {
if (!process.client) {
return;
}
if (dark) {
document.body.setAttribute('data-theme', 'dark');
localStorage.setItem('darkMode', 'dark');
} else {
document.body.removeAttribute('data-theme');
localStorage.removeItem('darkMode');
}
},
}
}