feat: add dark theme and project attribution
This commit is contained in:
@@ -4,6 +4,42 @@
|
||||
*/
|
||||
|
||||
document.addEventListener('DOMContentLoaded', function () {
|
||||
// Переключение светлой и тёмной темы
|
||||
const themeToggle = document.getElementById('theme-toggle');
|
||||
const themeIcon = themeToggle?.querySelector('.theme-icon');
|
||||
|
||||
function applyTheme(theme) {
|
||||
document.documentElement.dataset.theme = theme;
|
||||
|
||||
if (themeIcon) {
|
||||
themeIcon.textContent = theme === 'dark' ? '☀' : '☾';
|
||||
}
|
||||
|
||||
if (themeToggle) {
|
||||
const label = theme === 'dark'
|
||||
? 'Переключить на светлую тему'
|
||||
: 'Переключить на тёмную тему';
|
||||
|
||||
themeToggle.setAttribute('aria-label', label);
|
||||
themeToggle.setAttribute('title', label);
|
||||
}
|
||||
}
|
||||
|
||||
applyTheme(document.documentElement.dataset.theme || 'light');
|
||||
|
||||
themeToggle?.addEventListener('click', function () {
|
||||
const nextTheme =
|
||||
document.documentElement.dataset.theme === 'dark' ? 'light' : 'dark';
|
||||
|
||||
applyTheme(nextTheme);
|
||||
|
||||
try {
|
||||
localStorage.setItem('phone-store-theme', nextTheme);
|
||||
} catch (error) {
|
||||
// Тема останется активной до перезагрузки страницы.
|
||||
}
|
||||
});
|
||||
|
||||
// Автоматическое скрытие flash-сообщений через 4 секунды
|
||||
const flashes = document.querySelectorAll('.flash');
|
||||
flashes.forEach(function (flash) {
|
||||
|
||||
Reference in New Issue
Block a user