|
1 | | -document.addEventListener('DOMContentLoaded', function() { |
2 | | - const path = window.location.pathname; // 获取当前URL路径 |
3 | | - let pathParts = path.split('/'); |
4 | | - pathParts = pathParts.filter(item => item !== ""); |
5 | | - const book_hash = pathParts[pathParts.indexOf('book') + 1]; |
| 1 | +// 设置 cookie |
| 2 | +function setCookie(key, value) { |
| 3 | + const date = new Date(); |
| 4 | + date.setTime(date.getTime() + 3650 * 24 * 60 * 60 * 1000); // 3650天的毫秒数 |
| 5 | + const expires = "expires=" + date.toUTCString(); // 转换为 UTC 格式 |
| 6 | + document.cookie = `${key}=${value}; ${expires}; path=/;`; |
| 7 | +} |
6 | 8 |
|
7 | | - // 设置 cookie |
8 | | - function setCookie(key, value) { |
9 | | - const date = new Date(); |
10 | | - date.setTime(date.getTime() + 3650 * 24 * 60 * 60 * 1000); // 3650天的毫秒数 |
11 | | - const expires = "expires=" + date.toUTCString(); // 转换为 UTC 格式 |
12 | | - document.cookie = `${key}=${value}; ${expires}; path=/;`; |
13 | | - } |
14 | | - |
15 | | - // 解析指定 key 的 Cookie |
16 | | - function getCookie(key) { |
17 | | - // 分割所有 Cookie 为数组 |
18 | | - const cookies = document.cookie.split('; '); |
19 | | - for (const cookie of cookies) { |
20 | | - // 分割键和值 |
21 | | - const [cookieKey, cookieValue] = cookie.split('='); |
22 | | - // 解码并返回匹配的值 |
23 | | - if (cookieKey === key) { |
24 | | - return decodeURIComponent(cookieValue); |
25 | | - } |
| 9 | +// 解析指定 key 的 Cookie |
| 10 | +function getCookie(key) { |
| 11 | + // 分割所有 Cookie 为数组 |
| 12 | + const cookies = document.cookie.split('; '); |
| 13 | + for (const cookie of cookies) { |
| 14 | + // 分割键和值 |
| 15 | + const [cookieKey, cookieValue] = cookie.split('='); |
| 16 | + // 解码并返回匹配的值 |
| 17 | + if (cookieKey === key) { |
| 18 | + return decodeURIComponent(cookieValue); |
26 | 19 | } |
27 | | - return null; // 未找到 |
28 | 20 | } |
| 21 | + return null; // 未找到 |
| 22 | +} |
| 23 | + |
| 24 | +function deleteCookie(name) { |
| 25 | + // 设置 Cookie 过期时间为过去(例如:1970年1月1日) |
| 26 | + document.cookie = `${name}=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;`; |
| 27 | +} |
29 | 28 |
|
30 | | - function deleteCookie(name) { |
31 | | - // 设置 Cookie 过期时间为过去(例如:1970年1月1日) |
32 | | - document.cookie = `${name}=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;`; |
| 29 | +function updateFontFamily(fontFamily, fontFamilyInput) { |
| 30 | + if (fontFamily == "custom") { |
| 31 | + document.body.style.fontFamily = fontFamilyInput; |
| 32 | + } else { |
| 33 | + document.body.style.fontFamily = fontFamily; |
33 | 34 | } |
| 35 | +} |
| 36 | + |
| 37 | +document.addEventListener('DOMContentLoaded', function() { |
| 38 | + const path = window.location.pathname; // 获取当前URL路径 |
| 39 | + let pathParts = path.split('/'); |
| 40 | + pathParts = pathParts.filter(item => item !== ""); |
| 41 | + const book_hash = pathParts[pathParts.indexOf('book') + 1]; |
34 | 42 |
|
35 | 43 | let kindleMode = getCookie("kindle-mode") || "false"; |
36 | 44 |
|
@@ -81,14 +89,22 @@ document.addEventListener('DOMContentLoaded', function() { |
81 | 89 | // 主题切换功能 |
82 | 90 | const themeToggle = document.getElementById('themeToggle'); |
83 | 91 | const themeIcon = themeToggle.querySelector('i'); |
| 92 | + let fontFamily = "system-ui, -apple-system, sans-serif"; |
| 93 | + let fontFamilyInput = null; |
84 | 94 |
|
85 | 95 | // 检查本地存储中的主题设置 |
86 | 96 | let currentTheme = 'light'; |
87 | 97 | if (!isKindleMode()) { |
88 | 98 | currentTheme = localStorage.getItem('theme'); |
| 99 | + fontFamily = localStorage.getItem('font_family') || "system-ui, -apple-system, sans-serif"; |
| 100 | + fontFamilyInput = localStorage.getItem('font_family_input'); |
89 | 101 | } else { |
90 | 102 | currentTheme = getCookie('theme'); |
| 103 | + fontFamily = getCookie('font_family') || "system-ui, -apple-system, sans-serif"; |
| 104 | + fontFamilyInput = getCookie('font_family_input'); |
91 | 105 | } |
| 106 | + |
| 107 | + updateFontFamily(fontFamily, fontFamilyInput); |
92 | 108 |
|
93 | 109 | // 应用保存的主题 |
94 | 110 | if (currentTheme === 'dark') { |
|
0 commit comments