You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
19 lines
692 B
JavaScript
19 lines
692 B
JavaScript
3 weeks ago
|
function detectTheme() {
|
||
|
if (window.matchMedia('(prefers-color-scheme: dark)').matches) {
|
||
|
// Dark mode
|
||
|
console.log("Dark mode detected");
|
||
|
// Add your dark mode styles or trigger a CSS class change here
|
||
|
document.body.classList.add('dark-mode');
|
||
|
} else {
|
||
|
// Light mode
|
||
|
console.log("Light mode detected");
|
||
|
// Add your light mode styles or trigger a CSS class change here
|
||
|
document.body.classList.add('light-mode');
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// Call the function to detect the initial theme
|
||
|
detectTheme();
|
||
|
|
||
|
// Listen for changes in the system preference
|
||
|
window.matchMedia('(prefers-color-scheme: dark)').addEventListener('change', detectTheme);
|