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
831 B
JavaScript

export default {
methods: {
detectDark() {
if (!process.client) {
return false;
}
if (localStorage.getItem('darkMode') !== null) {
return localStorage.getItem('darkMode') === 'dark';
}
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.setItem('darkMode', 'light');
}
},
}
}