Skip to content

Commit

Permalink
Reader improve
Browse files Browse the repository at this point in the history
book title
  • Loading branch information
lkxnif committed Dec 26, 2024
1 parent 1ba2b1c commit 810f8d2
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions reader.html
Original file line number Diff line number Diff line change
Expand Up @@ -620,6 +620,15 @@ <h1 class="toolbar-title" id="book-title">加载中...</h1>
return;
}

// 加载books.json获取书籍信息
const booksResponse = await fetch('data/books.json');
if (!booksResponse.ok) {
throw new Error('无法加载书籍数据');
}
const booksData = await booksResponse.json();
const bookInfo = booksData.books.find(book => book.path === bookPath);
const bookTitle = bookInfo ? bookInfo.title : '未知书籍';

const baseUrl = document.querySelector('base')?.href || window.location.origin + window.location.pathname.replace(/\/[^/]*$/, '/');
const cleanPath = bookPath.replace(/^\/+/, '').replace(/^data\/+/, 'data/');
const fullPath = new URL(cleanPath, baseUrl).href;
Expand Down Expand Up @@ -668,8 +677,9 @@ <h1 class="toolbar-title" id="book-title">加载中...</h1>
});

reader.on('loaded', (data) => {
document.getElementById('book-title').textContent = data.title;
document.title = data.title + ' - 电子书阅读器';
// 使用books.json中的标题
document.getElementById('book-title').textContent = bookTitle;
document.title = bookTitle + ' - 电子书阅读器';
progress.min = "1";
progress.max = data.totalPages;
progress.value = "1";
Expand Down

0 comments on commit 810f8d2

Please sign in to comment.