Skip to content

Commit fc51c75

Browse files
committed
feat: code by Trae
1 parent 9b94427 commit fc51c75

3 files changed

Lines changed: 107 additions & 6 deletions

File tree

epub_browser/assets/chapter.css

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1359,4 +1359,41 @@ body {
13591359
.css-controls {
13601360
grid-template-columns: 1fr;
13611361
}
1362+
}
1363+
1364+
/* 加载动画样式 */
1365+
.loading-overlay {
1366+
position: fixed;
1367+
top: 0;
1368+
left: 0;
1369+
width: 100%;
1370+
height: 100%;
1371+
background-color: rgba(255, 255, 255, 0.95);
1372+
display: flex;
1373+
justify-content: center;
1374+
align-items: center;
1375+
z-index: 9999;
1376+
}
1377+
1378+
.loading-spinner {
1379+
width: 50px;
1380+
height: 50px;
1381+
border: 5px solid #f3f3f3;
1382+
border-top: 5px solid var(--primary);
1383+
border-radius: 50%;
1384+
animation: spin 1s linear infinite;
1385+
}
1386+
1387+
@keyframes spin {
1388+
0% { transform: rotate(0deg); }
1389+
100% { transform: rotate(360deg); }
1390+
}
1391+
1392+
.dark-mode .loading-overlay {
1393+
background-color: rgba(0, 0, 0, 0.95);
1394+
}
1395+
1396+
.dark-mode .loading-spinner {
1397+
border: 5px solid #333;
1398+
border-top: 5px solid var(--primary);
13621399
}

epub_browser/assets/chapter.js

Lines changed: 69 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,39 @@ async function scopeEBStyles(scopeSelector = '[data-eb-styles]') {
305305

306306

307307
function initScript() {
308+
// 创建加载动画元素
309+
function createLoadingOverlay() {
310+
const overlay = document.createElement('div');
311+
overlay.className = 'loading-overlay';
312+
overlay.id = 'loadingOverlay';
313+
314+
const spinner = document.createElement('div');
315+
spinner.className = 'loading-spinner';
316+
317+
overlay.appendChild(spinner);
318+
document.body.appendChild(overlay);
319+
}
320+
321+
// 显示加载动画
322+
function showLoading() {
323+
const overlay = document.getElementById('loadingOverlay');
324+
if (overlay) {
325+
overlay.style.display = 'flex';
326+
}
327+
}
328+
329+
// 隐藏加载动画
330+
function hideLoading() {
331+
const overlay = document.getElementById('loadingOverlay');
332+
if (overlay) {
333+
overlay.style.display = 'none';
334+
}
335+
}
336+
337+
// 初始化加载动画
338+
createLoadingOverlay();
339+
showLoading();
340+
308341
// 样式重写,增加区域限定
309342
scopeEBStyles();
310343

@@ -583,6 +616,8 @@ function initScript() {
583616

584617
// 创建页面 - 使用 CSS Column 实现
585618
function createPages() {
619+
showLoading();
620+
586621
// 保存原始内容
587622
const originalContent = preprocessContent(content);
588623

@@ -633,6 +668,10 @@ function initScript() {
633668
setTimeout(() => {
634669
calculateTotalPages();
635670
pageJumpInput.setAttribute('max', totalPages);
671+
// 延迟隐藏加载动画,确保页面完全渲染
672+
setTimeout(function() {
673+
hideLoading();
674+
}, 500);
636675
}, 200);
637676
}, 200);
638677
}
@@ -1097,8 +1136,8 @@ function initScript() {
10971136
const contentContainer = document.querySelector('.content-container');
10981137
const ebContent = document.getElementById('eb-content');
10991138

1100-
// 应用保存的状态
1101-
if (isPureModeEnabled) {
1139+
// 应用保存的状态 - 只在翻页模式下生效
1140+
if (isPureModeEnabled && isPaginationMode) {
11021141
// 隐藏工具栏
11031142
navigation.style.display = 'none';
11041143

@@ -1166,6 +1205,12 @@ function initScript() {
11661205

11671206
// 切换纯净阅读模式
11681207
function togglePureMode() {
1208+
// 只在翻页模式下才能切换纯净阅读模式
1209+
if (!isPaginationMode) {
1210+
showNotification('Pure reading mode is only available in page-turning mode', 'info');
1211+
return;
1212+
}
1213+
11691214
isPureModeEnabled = !isPureModeEnabled;
11701215
savePureModeState();
11711216
updatePureModeButton();
@@ -1202,7 +1247,7 @@ function initScript() {
12021247
contentContainer.style.marginBottom = '0';
12031248
ebContent.style.minHeight = 'calc(100vh - 80px)'; // 减去页面顶部和底部的 padding
12041249

1205-
showNotification('Pure reading mode enabled', 'info');
1250+
showNotification('Pure reading mode enabled. You can click the "Click" button to enable edge-click page turning, or use Spacebar and arrow keys for page navigation.', 'info');
12061251
} else {
12071252
// 显示工具栏
12081253
navigation.style.display = 'flex';
@@ -1276,8 +1321,19 @@ function initScript() {
12761321
const centerAreaHeight = rect.height * 0.3;
12771322

12781323
if (Math.abs(e.clientX - centerX) < centerAreaWidth && Math.abs(e.clientY - centerY) < centerAreaHeight) {
1279-
// 点击中间部分,无论设备类型,都切换纯净模式
1280-
togglePureMode();
1324+
// 点击中间部分,只有在翻页模式下才切换纯净模式
1325+
if (isPaginationMode) {
1326+
// 区分桌面端和移动端的行为
1327+
if (isMobile()) {
1328+
// 移动端:点击中间部分切换纯净模式
1329+
togglePureMode();
1330+
} else {
1331+
// 桌面端:只有在纯净阅读模式已开启时,点击中间部分才关闭纯净模式
1332+
if (isPureModeEnabled) {
1333+
togglePureMode();
1334+
}
1335+
}
1336+
}
12811337
}
12821338
});
12831339

@@ -1303,6 +1359,14 @@ function initScript() {
13031359
showNotification('Click edge to turn page disabled', 'info');
13041360
}
13051361
});
1362+
1363+
// 页面加载完成后隐藏加载动画
1364+
window.addEventListener('load', function() {
1365+
// 延迟隐藏加载动画,确保页面完全渲染
1366+
setTimeout(function() {
1367+
hideLoading();
1368+
}, 500);
1369+
});
13061370

13071371
// 自定义 css
13081372
customCssFunc();

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
setup(
88
name="epub-browser", # 在PyPI上显示的项目名称
9-
version="1.7.8", # 初始版本号
9+
version="1.7.9", # 初始版本号
1010
author="dfface", # 作者名
1111
author_email="dfface@sina.com", # 作者邮箱
1212
keywords="epub reader html export browser convert calibre-web calibre kindle web server local",

0 commit comments

Comments
 (0)