// 背景遮罩:夜间主题下给壁纸加暗色遮罩,可开关 + 调明暗度(存 localStorage) // Wallpaper dim: darkens the wallpaper under dark theme, with toggle + opacity // control (persisted in localStorage) (function () { const KEY_ON = 'hearth-mask-enabled'; const KEY_ALPHA = 'hearth-mask-alpha'; // 判断当前是否深色主题(强制深色,或跟随系统且系统为深色) // Whether the current theme is dark (forced dark, or follow-system + system dark) function isDark() { const t = window.theme.get(); if (t === 'dark') return true; if (t === 'light') return false; return window.matchMedia('(prefers-color-scheme: dark)').matches; } window.mask = { enabled() { return localStorage.getItem(KEY_ON) === '1'; }, alpha() { return parseFloat(localStorage.getItem(KEY_ALPHA) || '0.55'); }, setEnabled(on) { localStorage.setItem(KEY_ON, on ? '1' : '0'); this.apply(); }, setAlpha(a) { localStorage.setItem(KEY_ALPHA, String(a)); this.apply(); }, // 应用遮罩:仅深色主题且启用时显示(透明度 = 明暗度) // Apply: show only under dark theme when enabled (opacity = alpha) apply() { const el = document.getElementById('wallpaper-dim'); if (!el) return; el.style.opacity = (isDark() && this.enabled()) ? String(this.alpha()) : '0'; }, }; })();