Spaces:
Paused
Paused
Download novel-reader/src/readerSettings.js from tanlang002/tupload07: direct link, hf CLI and curl.
- Browser
- Download file 1.14 kB
-
https://huggingface.co/spaces/tanlang002/tupload07/resolve/main/novel-reader/src/readerSettings.js
- Command line
-
hf download hf://spaces/tanlang002/tupload07/novel-reader/src/readerSettings.js
-
curl -L -o readerSettings.js https://huggingface.co/spaces/tanlang002/tupload07/resolve/main/novel-reader/src/readerSettings.js
1.14 kB
| /* 阅读器设置:字号 / 背景 / 日夜模式 / 预设样式,持久化到 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)); | |
| } | |