Skip to content

Commit 1b77ccd

Browse files
committed
feat: code by Trae
1 parent e69d24e commit 1b77ccd

4 files changed

Lines changed: 103 additions & 3 deletions

File tree

README.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
[![license](https://img.shields.io/github/license/dfface/epub-browser)](https://pypi.org/project/epub-browser/)
88
![PyPI - Downloads](https://img.shields.io/pypi/dd/epub-browser)
99

10-
A simple and modern web E-book reader, which allows you to read e-books within a browser.
10+
A modern web-based EPUB reader with library management, dark mode, Kindle optimization, code highlighting, and PWA support for an enhanced reading experience across devices.
1111

1212
Try it online: [https://epub-browser-test.yuhan.tech](https://epub-browser-test.yuhan.tech)
1313

@@ -31,7 +31,7 @@ It now supports the following features:
3131

3232
- **Mobile device compatibility**: Especially for Kindle users—remember to tap *Not Kindle* on the homepage header to enable Kindle Mode for an optimized experience.
3333

34-
- **Code highlighting** (disabled in Kindle Mode).
34+
- **Code highlighting** (disabled in Kindle Mode) with theme synchronization.
3535

3636
- **Reading position retention**: Restores your last-read chapter (supported on all devices including Kindle) and your last-read location (supported on all devices *except* Kindle).
3737

@@ -54,6 +54,12 @@ It now supports the following features:
5454

5555
- **Watchdog utility**: Monitors the user-specified directory (or the directory containing EPUB files) with `--watch` parameter. Automatically adds newly added or updated EPUB files to the library.
5656

57+
- **Progressive Web App (PWA)**: Installable as a native app on supported devices for a more app-like experience.
58+
59+
- **Pure Reading Mode**: Hides all toolbars for distraction-free reading, toggleable by clicking the center of the screen.
60+
61+
- **Cache management**: Update button in library to clear Service Worker cache and refresh content.
62+
5763

5864
## Usage
5965

epub_browser/assets/chapter.js

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1072,6 +1072,96 @@ function initScript() {
10721072
// 监听整个 body 的点击事件
10731073
document.body.addEventListener('click', handleClickPage);
10741074

1075+
// 纯净阅读模式
1076+
let isPureModeEnabled = false;
1077+
const togglePureModeBtn = document.getElementById('togglePureMode');
1078+
1079+
// 初始化纯净阅读模式状态
1080+
function initPureModeState() {
1081+
if (!isKindleMode()) {
1082+
isPureModeEnabled = localStorage.getItem('pureModeEnabled') === 'true';
1083+
} else {
1084+
isPureModeEnabled = getCookie('pureModeEnabled') === 'true';
1085+
}
1086+
updatePureModeButton();
1087+
1088+
// 应用保存的状态
1089+
if (isPureModeEnabled) {
1090+
document.querySelector('.navigation').style.display = 'none';
1091+
document.querySelector('.top-controls').style.display = 'none';
1092+
document.querySelector('.reading-controls').style.display = 'none';
1093+
}
1094+
}
1095+
1096+
// 保存纯净阅读模式状态
1097+
function savePureModeState() {
1098+
if (!isKindleMode()) {
1099+
localStorage.setItem('pureModeEnabled', isPureModeEnabled.toString());
1100+
} else {
1101+
setCookie('pureModeEnabled', isPureModeEnabled.toString());
1102+
}
1103+
}
1104+
1105+
// 切换纯净阅读模式
1106+
function togglePureMode() {
1107+
isPureModeEnabled = !isPureModeEnabled;
1108+
savePureModeState();
1109+
updatePureModeButton();
1110+
1111+
if (isPureModeEnabled) {
1112+
// 隐藏工具栏
1113+
document.querySelector('.navigation').style.display = 'none';
1114+
document.querySelector('.top-controls').style.display = 'none';
1115+
document.querySelector('.reading-controls').style.display = 'none';
1116+
showNotification('Pure reading mode enabled', 'info');
1117+
} else {
1118+
// 显示工具栏
1119+
document.querySelector('.navigation').style.display = 'flex';
1120+
document.querySelector('.top-controls').style.display = 'flex';
1121+
document.querySelector('.reading-controls').style.display = 'flex';
1122+
showNotification('Pure reading mode disabled', 'info');
1123+
}
1124+
}
1125+
1126+
// 更新纯净模式按钮状态
1127+
function updatePureModeButton() {
1128+
if (isPureModeEnabled) {
1129+
togglePureModeBtn.classList.add('active');
1130+
togglePureModeBtn.style.background = 'var(--primary)';
1131+
togglePureModeBtn.style.color = 'white';
1132+
} else {
1133+
togglePureModeBtn.classList.remove('active');
1134+
togglePureModeBtn.style.background = '';
1135+
togglePureModeBtn.style.color = '';
1136+
}
1137+
}
1138+
1139+
// 点击文档中心时显示工具栏
1140+
document.getElementById('eb-content').addEventListener('click', function(e) {
1141+
if (isPureModeEnabled) {
1142+
// 计算点击位置是否在文档中心
1143+
const screenWidth = window.innerWidth;
1144+
const screenHeight = window.innerHeight;
1145+
const centerX = screenWidth / 2;
1146+
const centerY = screenHeight / 2;
1147+
const centerArea = Math.min(screenWidth, screenHeight) * 0.3; // 中心30%区域
1148+
1149+
if (Math.abs(e.clientX - centerX) < centerArea && Math.abs(e.clientY - centerY) < centerArea) {
1150+
togglePureMode();
1151+
}
1152+
}
1153+
});
1154+
1155+
// 纯净模式按钮点击事件
1156+
if (togglePureModeBtn) {
1157+
togglePureModeBtn.addEventListener('click', function() {
1158+
togglePureMode();
1159+
});
1160+
}
1161+
1162+
// 初始化纯净阅读模式状态
1163+
initPureModeState();
1164+
10751165
// 点击翻页按钮点击事件
10761166
toggleClickPageBtn.addEventListener('click', function() {
10771167
isClickPageEnabled = !isClickPageEnabled;

epub_browser/processor.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -982,6 +982,10 @@ def create_chapter_template(self, content, style_links, chapter_index, chapter_t
982982
<i class="fas fa-hand-pointer"></i>
983983
<span class="control-name">Click</span>
984984
</div>
985+
<div class="control-btn" id="togglePureMode" title="Pure reading mode">
986+
<i class="fas fa-book-open"></i>
987+
<span class="control-name">Pure</span>
988+
</div>
985989
</div>
986990
<div style="display: none; flex-direction: row;" class="page-height-adjustment">
987991
<span>

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.6", # 初始版本号
9+
version="1.7.7", # 初始版本号
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)