set theme color outside of preference (console error)
This commit is contained in:
parent
befda89a25
commit
2ee8042644
1 changed files with 4 additions and 1 deletions
|
|
@ -20,6 +20,7 @@ window.onload = () => {
|
||||||
}
|
}
|
||||||
|
|
||||||
reflectPreference();
|
reflectPreference();
|
||||||
|
updateThemeColor();
|
||||||
|
|
||||||
lightThemeToggle.addEventListener('click', () => onClick('light'));
|
lightThemeToggle.addEventListener('click', () => onClick('light'));
|
||||||
darkThemeToggle.addEventListener('click', () => onClick('dark'));
|
darkThemeToggle.addEventListener('click', () => onClick('dark'));
|
||||||
|
|
@ -58,7 +59,9 @@ function reflectPreference() {
|
||||||
document.firstElementChild.setAttribute('data-theme', theme.value);
|
document.firstElementChild.setAttribute('data-theme', theme.value);
|
||||||
document.querySelector('#light-theme-toggle')?.setAttribute('aria-label', lightLabel);
|
document.querySelector('#light-theme-toggle')?.setAttribute('aria-label', lightLabel);
|
||||||
document.querySelector('#dark-theme-toggle')?.setAttribute('aria-label', darkLabel);
|
document.querySelector('#dark-theme-toggle')?.setAttribute('aria-label', darkLabel);
|
||||||
// adjust the theme color
|
}
|
||||||
|
|
||||||
|
function updateThemeColor() {
|
||||||
document
|
document
|
||||||
.querySelector('meta[name="theme-color"]')
|
.querySelector('meta[name="theme-color"]')
|
||||||
.setAttribute('content', theme.value === 'dark' ? themeColors.dark : themeColors.light);
|
.setAttribute('content', theme.value === 'dark' ? themeColors.dark : themeColors.light);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue