随浏览器
This commit is contained in:
@@ -389,7 +389,6 @@ input:checked + .slider:before {
|
|||||||
font-size: 0.85rem;
|
font-size: 0.85rem;
|
||||||
font-weight: 500;
|
font-weight: 500;
|
||||||
color: var(--accent-indigo);
|
color: var(--accent-indigo);
|
||||||
margin-right: 8px;
|
|
||||||
opacity: 0.9;
|
opacity: 0.9;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -15,7 +15,11 @@
|
|||||||
const savedTheme = localStorage.getItem('theme');
|
const savedTheme = localStorage.getItem('theme');
|
||||||
const settings = window.SITE_SETTINGS || {};
|
const settings = window.SITE_SETTINGS || {};
|
||||||
const defaultTheme = settings.default_theme || 'dark';
|
const defaultTheme = settings.default_theme || 'dark';
|
||||||
const theme = savedTheme || defaultTheme;
|
let theme = savedTheme || defaultTheme;
|
||||||
|
|
||||||
|
if (theme === 'auto') {
|
||||||
|
theme = window.matchMedia('(prefers-color-scheme: light)').matches ? 'light' : 'dark';
|
||||||
|
}
|
||||||
|
|
||||||
if (theme === 'light') {
|
if (theme === 'light') {
|
||||||
document.documentElement.classList.add('light-theme');
|
document.documentElement.classList.add('light-theme');
|
||||||
@@ -203,10 +207,10 @@
|
|||||||
<div class="chart-card chart-card-gauges" id="gaugesCard">
|
<div class="chart-card chart-card-gauges" id="gaugesCard">
|
||||||
<div class="chart-card-header">
|
<div class="chart-card-header">
|
||||||
<h2 class="chart-title">
|
<h2 class="chart-title">
|
||||||
<span class="title-time" id="gaugesTime"></span>
|
|
||||||
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" class="chart-title-icon">
|
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" class="chart-title-icon">
|
||||||
<path d="M12 20V10M18 20V4M6 20v-4"/>
|
<path d="M12 20V10M18 20V4M6 20v-4"/>
|
||||||
</svg>
|
</svg>
|
||||||
|
<span class="title-time" id="gaugesTime"></span>
|
||||||
资源使用概览
|
资源使用概览
|
||||||
</h2>
|
</h2>
|
||||||
</div>
|
</div>
|
||||||
@@ -359,6 +363,7 @@
|
|||||||
<select id="defaultThemeInput" style="padding: 10px 14px; background: var(--bg-input); border: 1px solid var(--border-color); border-radius: var(--radius-sm); color: var(--text-primary);">
|
<select id="defaultThemeInput" style="padding: 10px 14px; background: var(--bg-input); border: 1px solid var(--border-color); border-radius: var(--radius-sm); color: var(--text-primary);">
|
||||||
<option value="dark">默认夜间模式</option>
|
<option value="dark">默认夜间模式</option>
|
||||||
<option value="light">默认白天模式</option>
|
<option value="light">默认白天模式</option>
|
||||||
|
<option value="auto">跟随浏览器/系统</option>
|
||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
<div class="form-actions" style="margin-top: 25px; display: flex; justify-content: flex-end;">
|
<div class="form-actions" style="margin-top: 25px; display: flex; justify-content: flex-end;">
|
||||||
|
|||||||
@@ -164,21 +164,23 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
function applyTheme(theme) {
|
function applyTheme(theme) {
|
||||||
const isLight = theme === 'light';
|
let actualTheme = theme;
|
||||||
|
if (theme === 'auto') {
|
||||||
|
actualTheme = window.matchMedia('(prefers-color-scheme: light)').matches ? 'light' : 'dark';
|
||||||
|
}
|
||||||
|
|
||||||
|
const isLight = actualTheme === 'light';
|
||||||
dom.themeToggle.checked = isLight;
|
dom.themeToggle.checked = isLight;
|
||||||
document.documentElement.classList.toggle('light-theme', isLight);
|
document.documentElement.classList.toggle('light-theme', isLight);
|
||||||
updateThemeIcons(theme);
|
updateThemeIcons(actualTheme);
|
||||||
}
|
}
|
||||||
|
|
||||||
function updateThemeIcons(theme) {
|
function updateThemeIcons(theme) {
|
||||||
|
// Icons are in the slider, we adjust their opacity to show which one is active
|
||||||
if (theme === 'light') {
|
if (theme === 'light') {
|
||||||
dom.sunIcon.style.display = 'block'; // Always show both in slider, but might adjust opacity
|
|
||||||
dom.moonIcon.style.display = 'block';
|
|
||||||
dom.sunIcon.style.opacity = '0.3';
|
dom.sunIcon.style.opacity = '0.3';
|
||||||
dom.moonIcon.style.opacity = '1';
|
dom.moonIcon.style.opacity = '1';
|
||||||
} else {
|
} else {
|
||||||
dom.sunIcon.style.display = 'block';
|
|
||||||
dom.moonIcon.style.display = 'block';
|
|
||||||
dom.sunIcon.style.opacity = '1';
|
dom.sunIcon.style.opacity = '1';
|
||||||
dom.moonIcon.style.opacity = '0.3';
|
dom.moonIcon.style.opacity = '0.3';
|
||||||
}
|
}
|
||||||
@@ -487,13 +489,18 @@
|
|||||||
|
|
||||||
// Handle Theme Priority: localStorage > Site Default
|
// Handle Theme Priority: localStorage > Site Default
|
||||||
const savedTheme = localStorage.getItem('theme');
|
const savedTheme = localStorage.getItem('theme');
|
||||||
if (savedTheme) {
|
const themeToApply = savedTheme || settings.default_theme || 'dark';
|
||||||
applyTheme(savedTheme);
|
applyTheme(themeToApply);
|
||||||
} else if (settings.default_theme) {
|
|
||||||
applyTheme(settings.default_theme);
|
// Listen for system theme changes if set to auto
|
||||||
} else {
|
window.matchMedia('(prefers-color-scheme: light)').addEventListener('change', () => {
|
||||||
applyTheme('dark'); // Fallback
|
const currentSavedTheme = localStorage.getItem('theme');
|
||||||
|
const defaultTheme = window.SITE_SETTINGS ? window.SITE_SETTINGS.default_theme : 'dark';
|
||||||
|
const activeTheme = currentSavedTheme || defaultTheme;
|
||||||
|
if (activeTheme === 'auto') {
|
||||||
|
applyTheme('auto');
|
||||||
}
|
}
|
||||||
|
});
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error('Error loading site settings:', err);
|
console.error('Error loading site settings:', err);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user