@@ -0,0 +1,47 @@
|
||||
(function() {
|
||||
var STORAGE_KEY = 'aegisone_service_theme';
|
||||
var themes = ['system', 'dark', 'light'];
|
||||
|
||||
function getSystemTheme() {
|
||||
return window.matchMedia('(prefers-color-scheme: light)').matches ? 'light' : 'dark';
|
||||
}
|
||||
|
||||
function applyTheme(theme) {
|
||||
var resolved = theme === 'system' ? getSystemTheme() : theme;
|
||||
document.documentElement.setAttribute('data-theme', resolved);
|
||||
var label = document.getElementById('theme-label');
|
||||
if (label) {
|
||||
var names = { system: 'Авто', dark: 'Тёмная', light: 'Светлая' };
|
||||
label.textContent = names[theme] || 'Авто';
|
||||
}
|
||||
var btn = document.getElementById('theme-btn');
|
||||
if (btn) {
|
||||
var icons = { system: '🖥', dark: '🌙', light: '☀️' };
|
||||
btn.textContent = icons[theme] || '🖥';
|
||||
}
|
||||
}
|
||||
|
||||
function getNextTheme(current) {
|
||||
var idx = themes.indexOf(current);
|
||||
return themes[(idx + 1) % themes.length];
|
||||
}
|
||||
|
||||
function toggleTheme() {
|
||||
var current = localStorage.getItem(STORAGE_KEY) || 'system';
|
||||
var next = getNextTheme(current);
|
||||
localStorage.setItem(STORAGE_KEY, next);
|
||||
applyTheme(next);
|
||||
}
|
||||
|
||||
var saved = localStorage.getItem(STORAGE_KEY) || 'system';
|
||||
applyTheme(saved);
|
||||
|
||||
window.matchMedia('(prefers-color-scheme: light)').addEventListener('change', function() {
|
||||
var current = localStorage.getItem(STORAGE_KEY) || 'system';
|
||||
if (current === 'system') {
|
||||
applyTheme('system');
|
||||
}
|
||||
});
|
||||
|
||||
window.toggleTheme = toggleTheme;
|
||||
})();
|
||||
Reference in New Issue
Block a user