@@ -19,6 +19,50 @@ function showNotification(message, type) {
1919 } , 3000 ) ;
2020}
2121
22+ // 设置 cookie
23+ function setCookie ( key , value ) {
24+ var date = new Date ( ) ;
25+ date . setTime ( date . getTime ( ) + 3650 * 24 * 60 * 60 * 1000 ) ;
26+ var expires = "expires=" + date . toUTCString ( ) ;
27+ document . cookie = key + "=" + value + ";" + expires + "; path=/; SameSite=Lax" ;
28+ }
29+
30+ // 解析指定 key 的 Cookie —— Kindle 兼容版
31+ function getCookie ( key ) {
32+ var cookies = document . cookie . split ( '; ' ) ;
33+ // 替换 for...of 为传统 for 循环
34+ for ( var i = 0 ; i < cookies . length ; i ++ ) {
35+ var cookie = cookies [ i ] ;
36+ // 替换解构赋值
37+ var parts = cookie . split ( '=' ) ;
38+ var cookieKey = parts [ 0 ] ;
39+ var cookieValue = parts . slice ( 1 ) . join ( '=' ) ;
40+
41+ if ( cookieKey === key ) {
42+ return decodeURIComponent ( cookieValue ) ;
43+ }
44+ }
45+ return null ;
46+ }
47+
48+ function deleteCookie ( name ) {
49+ document . cookie = name + "=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;" ;
50+ }
51+
52+ // 检测是否是 Kindle 设备
53+ function isKindleMode ( ) {
54+ if ( window . epubBrowserCache && window . epubBrowserCache . kindle_mode !== undefined ) {
55+ return window . epubBrowserCache . kindle_mode === 'true' ;
56+ }
57+ var ua = navigator . userAgent . toLowerCase ( ) ;
58+ var isKindle = ua . indexOf ( 'kindle' ) !== - 1 || ua . indexOf ( 'silk' ) !== - 1 ;
59+ if ( ! window . epubBrowserCache ) {
60+ window . epubBrowserCache = { } ;
61+ }
62+ window . epubBrowserCache . kindle_mode = isKindle ? 'true' : 'false' ;
63+ return isKindle ;
64+ }
65+
2266function initScript ( ) {
2367 function loadBookMetadata ( callback ) {
2468 var metadataUrl = "/book-metadata.json" ;
@@ -100,36 +144,6 @@ function initScript() {
100144 window . onBookCardsLoaded ( ) ;
101145 }
102146 } ) ;
103-
104- // 设置 cookie
105- function setCookie ( key , value ) {
106- var date = new Date ( ) ;
107- date . setTime ( date . getTime ( ) + 3650 * 24 * 60 * 60 * 1000 ) ;
108- var expires = "expires=" + date . toUTCString ( ) ;
109- document . cookie = key + "=" + value + ";" + expires + "; path=/; SameSite=Lax" ;
110- }
111-
112- // 解析指定 key 的 Cookie —— Kindle 兼容版
113- function getCookie ( key ) {
114- var cookies = document . cookie . split ( '; ' ) ;
115- // 替换 for...of 为传统 for 循环
116- for ( var i = 0 ; i < cookies . length ; i ++ ) {
117- var cookie = cookies [ i ] ;
118- // 替换解构赋值
119- var parts = cookie . split ( '=' ) ;
120- var cookieKey = parts [ 0 ] ;
121- var cookieValue = parts . slice ( 1 ) . join ( '=' ) ;
122-
123- if ( cookieKey === key ) {
124- return decodeURIComponent ( cookieValue ) ;
125- }
126- }
127- return null ;
128- }
129-
130- function deleteCookie ( name ) {
131- document . cookie = name + "=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;" ;
132- }
133147
134148 // 页面加载时恢复顺序
135149 function restoreOrder ( storageKey , elementClass ) {
@@ -155,20 +169,6 @@ function initScript() {
155169 }
156170 }
157171
158- // 检测是否是 Kindle 设备
159- function isKindleMode ( ) {
160- if ( window . epubBrowserCache && window . epubBrowserCache . kindle_mode !== undefined ) {
161- return window . epubBrowserCache . kindle_mode === 'true' ;
162- }
163- var ua = navigator . userAgent . toLowerCase ( ) ;
164- var isKindle = ua . indexOf ( 'kindle' ) !== - 1 || ua . indexOf ( 'silk' ) !== - 1 ;
165- if ( ! window . epubBrowserCache ) {
166- window . epubBrowserCache = { } ;
167- }
168- window . epubBrowserCache . kindle_mode = isKindle ? 'true' : 'false' ;
169- return isKindle ;
170- }
171-
172172 var USERNAME_KEY = 'epub_browser_username' ;
173173
174174 function getUsername ( ) {
@@ -198,8 +198,6 @@ function initScript() {
198198 }
199199 }
200200
201- window . getUsername = getUsername ;
202- window . setUsername = setUsername ;
203201 updateLoginDisplay ( ) ;
204202
205203 var loginCard = document . getElementById ( 'loginCard' ) ;
0 commit comments