Merge pull request #164 from TobiasBerg/docs-auto-theme
Set Dark/Light Mode in Docs Based on Browser Preference
This commit is contained in:
commit
a335d6835b
|
|
@ -1054,9 +1054,14 @@
|
||||||
icon.textContent = newTheme === 'light' ? '🌙' : '☀️';
|
icon.textContent = newTheme === 'light' ? '🌙' : '☀️';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getBrowserThemePreference() {
|
||||||
|
const prefersDarkMode = window.matchMedia('(prefers-color-scheme: dark)').matches;
|
||||||
|
return prefersDarkMode ? 'dark' : 'light';
|
||||||
|
}
|
||||||
|
|
||||||
// Load saved theme on page load
|
// Load saved theme on page load
|
||||||
(function() {
|
(function() {
|
||||||
const savedTheme = localStorage.getItem('theme') || 'light';
|
const savedTheme = localStorage.getItem('theme') || getBrowserThemePreference();
|
||||||
document.documentElement.setAttribute('data-theme', savedTheme);
|
document.documentElement.setAttribute('data-theme', savedTheme);
|
||||||
|
|
||||||
// Update icon
|
// Update icon
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue