/
Jonecuper
/
fb-reader-for-mozilla
Обзор
Документация
Войти
/
Jonecuper
/
fb-reader-for-mozilla
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
src/settings.js
191 строка
5 KB
Jonecuper
Initial commit: FB2 Night Reader v2.0
29 май 2026, 23:10
29 май 2026, 23:10
3e0c9d2
Код
Авторство
О чём код?
'use strict'; var FB2Settings = (function() { var DEFAULTS = { theme: 'light', bg: '#faf8f5', text: '#1a1a1a', link: '#0055cc', linkVisited: '#551a8b', fontFamily: 'Georgia, "Times New Roman", serif', fontSize: 16, lineHeight: 1.6, textAlign: 'justify', pageWidth: 45, marginTop: 2.5, marginBottom: 2.5, paraSpacing: 1, paraIndent: 0 }; var PRESETS = { light: { theme: 'light', bg: '#faf8f5', text: '#1a1a1a', link: '#0055cc', linkVisited: '#551a8b', citeBg: '#eeeeee', citeBorder: '#aaaaaa', tableBorder: '#aaaaaa', noteBg: '#f5f5b5', noteBorder: '#baba45', noteShadow: 'rgba(0,0,0,0.2)', tocBg: '#fff8dc', tocBorder: '#ffa500', tocText: '#000000', tocHoverBg: '#fffff0', tocShadow: 'rgba(0,0,0,0.2)' }, dark: { theme: 'dark', bg: '#1a1a1c', text: '#d4d4d4', link: '#7ea8d4', linkVisited: '#9a7ec4', citeBg: '#2a2a2e', citeBorder: '#555555', tableBorder: '#444444', noteBg: '#3a3a18', noteBorder: '#6a6a30', noteShadow: 'rgba(0,0,0,0.5)', tocBg: '#2a2a18', tocBorder: '#8a8a30', tocText: '#d4d4d4', tocHoverBg: '#3a3a28', tocShadow: 'rgba(0,0,0,0.5)' }, sepia: { theme: 'sepia', bg: '#f4ecd8', text: '#5b4636', link: '#8b5a2b', linkVisited: '#6b3a1b', citeBg: '#e8dcc8', citeBorder: '#c4b898', tableBorder: '#c4b898', noteBg: '#f0e4c8', noteBorder: '#c4b060', noteShadow: 'rgba(0,0,0,0.15)', tocBg: '#e8dcc8', tocBorder: '#c4b060', tocText: '#5b4636', tocHoverBg: '#f0e4d0', tocShadow: 'rgba(0,0,0,0.15)' }, slate: { theme: 'slate', bg: '#252B37', text: '#ccd2dd', link: '#8ca8d4', linkVisited: '#a08cc4', citeBg: '#2a3040', citeBorder: '#4a5468', tableBorder: '#4a5468', noteBg: '#3a3a28', noteBorder: '#6a6a48', noteShadow: 'rgba(0,0,0,0.4)', tocBg: '#2a3040', tocBorder: '#5a6478', tocText: '#ccd2dd', tocHoverBg: '#3a4050', tocShadow: 'rgba(0,0,0,0.4)' } }; function buildCSS(settings) { var s = settings || DEFAULTS; var lines = []; lines.push(':root {'); lines.push(' --fb-bg: ' + (s.bg || DEFAULTS.bg) + ';'); lines.push(' --fb-text: ' + s.text + ';'); lines.push(' --fb-link: ' + s.link + ';'); lines.push(' --fb-link-visited: ' + (s.linkVisited || s.link) + ';'); lines.push(' --fb-font-family: ' + s.fontFamily + ';'); lines.push(' --fb-font-size: ' + s.fontSize + 'px;'); lines.push(' --fb-line-height: ' + s.lineHeight + ';'); lines.push(' --fb-text-align: ' + s.textAlign + ';'); lines.push(' --fb-page-width: ' + s.pageWidth + 'em;'); lines.push(' --fb-margin-top: ' + s.marginTop + 'em;'); lines.push(' --fb-margin-bottom: ' + s.marginBottom + 'em;'); lines.push(' --fb-para-spacing: ' + s.paraSpacing + 'em;'); lines.push(' --fb-para-indent: ' + s.paraIndent + 'em;'); if (s.citeBg) lines.push(' --fb-cite-bg: ' + s.citeBg + ';'); if (s.citeBorder) lines.push(' --fb-cite-border: ' + s.citeBorder + ';'); if (s.tableBorder) lines.push(' --fb-table-border: ' + s.tableBorder + ';'); if (s.noteBg) lines.push(' --fb-note-bg: ' + s.noteBg + ';'); if (s.noteBorder) lines.push(' --fb-note-border: ' + s.noteBorder + ';'); if (s.noteShadow) lines.push(' --fb-note-shadow: ' + s.noteShadow + ';'); if (s.tocBg) lines.push(' --fb-toc-bg: ' + s.tocBg + ';'); if (s.tocBorder) lines.push(' --fb-toc-border: ' + s.tocBorder + ';'); if (s.tocText) lines.push(' --fb-toc-text: ' + s.tocText + ';'); if (s.tocHoverBg) lines.push(' --fb-toc-hover-bg: ' + s.tocHoverBg + ';'); if (s.tocShadow) lines.push(' --fb-toc-shadow: ' + s.tocShadow + ';'); lines.push('}'); return lines.join('\n'); } function applyPreset(name) { var preset = PRESETS[name]; if (!preset) return null; var merged = {}; var key; for (key in DEFAULTS) { if (DEFAULTS.hasOwnProperty(key)) { merged[key] = (preset[key] !== undefined) ? preset[key] : DEFAULTS[key]; } } for (key in preset) { if (preset.hasOwnProperty(key) && !(key in DEFAULTS)) { merged[key] = preset[key]; } } return merged; } function detectTheme(settings) { var presets = ['light', 'dark', 'sepia', 'slate']; for (var i = 0; i < presets.length; i++) { var name = presets[i]; var preset = PRESETS[name]; if (settings.bg === preset.bg && settings.text === preset.text && settings.link === preset.link) { return name; } } return 'custom'; } function mergeWithDefaults(user) { var merged = {}; var key; for (key in DEFAULTS) { if (DEFAULTS.hasOwnProperty(key)) { merged[key] = (user && user[key] !== undefined) ? user[key] : DEFAULTS[key]; } } if (user) { for (key in user) { if (user.hasOwnProperty(key) && !(key in DEFAULTS)) { merged[key] = user[key]; } } } return merged; } return { DEFAULTS: DEFAULTS, PRESETS: PRESETS, buildCSS: buildCSS, applyPreset: applyPreset, detectTheme: detectTheme, mergeWithDefaults: mergeWithDefaults }; })();