Skip to content

Commit

Permalink
reader
Browse files Browse the repository at this point in the history
  • Loading branch information
lkxnif committed Dec 26, 2024
1 parent a82f011 commit e82ef3a
Showing 1 changed file with 26 additions and 9 deletions.
35 changes: 26 additions & 9 deletions reader.html
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,16 @@ <h1 class="toolbar-title h6 mb-0" id="book-title">加载中...</h1>
}

console.log('文件大小:', (blob.size / 1024 / 1024).toFixed(2) + 'MB');
updateLoadingStatus('正在初始化阅��器...');
updateLoadingStatus('正在初始化阅读器...');

// 移除旧的加载动画
viewer.querySelector('.loading')?.remove();

// 创建新的渲染容器
const viewerDiv = document.createElement('div');
viewerDiv.id = 'epub-viewer';
viewerDiv.style.height = '100%';
viewer.appendChild(viewerDiv);

// 直接使用 blob 初始化
const book = ePub(blob);
Expand All @@ -202,27 +211,35 @@ <h1 class="toolbar-title h6 mb-0" id="book-title">加载中...</h1>
updateLoadingStatus('电子书准备就绪');
}).catch(error => {
console.error('电子书准备失败:', error);
throw error;
});

const rendition = book.renderTo('viewer', {
const rendition = book.renderTo('epub-viewer', {
width: '100%',
height: '100%',
spread: 'none',
flow: 'paginated',
minSpreadWidth: 800,
flow: 'scrolled-doc',
allowScriptedContent: true,
manager: 'default',
view: 'iframe'
manager: 'continuous'
});

// 设置渲染样式
rendition.themes.default({
'body': {
'padding': '20px',
'max-width': '100%',
'max-width': '800px',
'margin': '0 auto',
'font-family': 'system-ui, -apple-system, sans-serif',
'line-height': '1.6',
'background-color': 'var(--background-color)',
'color': 'var(--text-color)'
},
'p': {
'margin-bottom': '1em'
},
'img': {
'max-width': '100%',
'height': 'auto'
}
});

Expand Down Expand Up @@ -283,7 +300,7 @@ <h1 class="toolbar-title h6 mb-0" id="book-title">加载中...</h1>
});
});

// 键盘���制
// 键盘控制
document.addEventListener('keyup', event => {
if (event.key === 'ArrowLeft') rendition.prev();
if (event.key === 'ArrowRight') rendition.next();
Expand Down Expand Up @@ -311,7 +328,7 @@ <h1 class="toolbar-title h6 mb-0" id="book-title">加载中...</h1>
});

} catch (error) {
showError('初始化阅读器失败:' + (error.message || '未知错误'));
showError('初始化阅���器失败:' + (error.message || '未知错误'));
}
});
</script>
Expand Down

0 comments on commit e82ef3a

Please sign in to comment.