Spaces:
Paused
Paused
File size: 1,138 Bytes
6d2d8b6 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 | /* 阅读器设置:字号 / 背景 / 日夜模式 / 预设样式,持久化到 localStorage。 */
const STORAGE_KEY = 'reader_settings';
export const READER_PRESETS = [
{ id: 'default', name: '默认', bg: '#ffffff', color: '#26221f', dark: false },
{ id: 'paper', name: '羊皮纸', bg: '#f6eed9', color: '#3b3628', dark: false },
{ id: 'green', name: '护眼绿', bg: '#cfe8cf', color: '#2f3b2f', dark: false },
{ id: 'dark', name: '夜间', bg: '#1b1b1d', color: '#b9b9bd', dark: true },
];
export const DEFAULT_SETTINGS = {
fontSize: 18,
preset: 'default',
bg: '#ffffff',
color: '#26221f',
dark: false,
};
export function loadSettings() {
try {
const raw = localStorage.getItem(STORAGE_KEY);
if (!raw) return { ...DEFAULT_SETTINGS };
return { ...DEFAULT_SETTINGS, ...JSON.parse(raw) };
} catch {
return { ...DEFAULT_SETTINGS };
}
}
export function saveSettings(settings) {
try {
localStorage.setItem(STORAGE_KEY, JSON.stringify(settings));
} catch {
// 存储不可用时静默忽略
}
}
export function clampFontSize(size) {
return Math.min(30, Math.max(14, size));
}
|