Skip to content

Commit

Permalink
upd darkMode
Browse files Browse the repository at this point in the history
  • Loading branch information
alexy-os committed Nov 28, 2024
1 parent 4b5d5e9 commit 24fac49
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 5 deletions.
3 changes: 3 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
(function() {
const theme = localStorage.getItem('darkMode');
const systemTheme = window.matchMedia('(prefers-color-scheme: dark)').matches;
if (!theme && systemTheme) {
localStorage.setItem('darkMode', 'true');
}
if (theme === 'true' || (!theme && systemTheme)) {
document.documentElement.classList.add('dark');
}
Expand Down
28 changes: 23 additions & 5 deletions public/buildy/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,30 @@
<meta name="mobile-web-app-capable" content="yes">
<script>
(function() {
const theme = localStorage.getItem('darkMode');
const systemTheme = window.matchMedia('(prefers-color-scheme: dark)').matches;
if (theme === 'true' || (!theme && systemTheme)) {
document.documentElement.classList.add('dark');
try {
// Получаем текущее состояние темы
const theme = localStorage.getItem('darkMode');
const systemTheme = window.matchMedia('(prefers-color-scheme: dark)').matches;

// Если тема явно не установлена, устанавливаем значение на основе системных настроек
if (!theme && systemTheme) {
localStorage.setItem('darkMode', 'true');
}

// Применяем тему
if (theme === 'true' || (!theme && systemTheme)) {
document.documentElement.classList.add('dark');
document.querySelector('meta[name="theme-color"]')
.setAttribute('content', '#000000');
}
} catch (e) {
// В случае ошибки используем системные настройки
if (window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches) {
document.documentElement.classList.add('dark');
localStorage.setItem('darkMode', 'true');
}
}
})();
})();
</script>
<script src="./js/lib/tailwind.js"></script>
<script src="./js/lib/lucide.min.js"></script>
Expand Down

0 comments on commit 24fac49

Please sign in to comment.