logboard/app/static/js/error.js
2025-08-20 17:32:07 +03:00

50 lines
1.6 KiB
JavaScript

/**
* LogBoard+ - Скрипт страницы ошибок
* Автор: Сергей Антропов
* Сайт: https://devops.org.ru
*/
/**
* Переключает тему между светлой и темной
* Обновляет атрибут data-theme и сохраняет выбор в localStorage
*/
function toggleTheme() {
const html = document.documentElement;
const currentTheme = html.getAttribute('data-theme');
const newTheme = currentTheme === 'light' ? 'dark' : 'light';
html.setAttribute('data-theme', newTheme);
localStorage.setItem('lb_theme', newTheme);
// Update theme toggle button
const themeButton = document.querySelector('.theme-toggle');
if (themeButton) {
themeButton.textContent = newTheme === 'light' ? '🌙' : '☀️';
}
}
/**
* Инициализация темы при загрузке страницы
* Загружает сохраненную тему из localStorage
*/
document.addEventListener('DOMContentLoaded', function() {
const savedTheme = localStorage.getItem('lb_theme') || 'dark';
document.documentElement.setAttribute('data-theme', savedTheme);
// Update theme toggle button
const themeButton = document.querySelector('.theme-toggle');
if (themeButton) {
themeButton.textContent = savedTheme === 'light' ? '🌙' : '☀️';
}
});
/**
* Горячая клавиша для переключения темы (Ctrl+T)
*/
document.addEventListener('keydown', function(e) {
if (e.ctrlKey && e.key === 't') {
e.preventDefault();
toggleTheme();
}
});