2021-09-26 13:00:26 +00:00
|
|
|
|
<!DOCTYPE html>
|
|
|
|
|
<html>
|
2021-10-03 09:05:31 +00:00
|
|
|
|
|
2021-09-29 08:07:22 +00:00
|
|
|
|
<head>
|
2021-09-26 13:00:26 +00:00
|
|
|
|
<meta charset="utf-8">
|
|
|
|
|
<meta name="viewport"
|
2021-09-29 08:07:22 +00:00
|
|
|
|
content="width=device-width,initial-scale=1.0,maximum-scale=1.0,minimum-scale=1.0,user-scalable=no">
|
2021-09-26 13:00:26 +00:00
|
|
|
|
<title>EPUB</title>
|
|
|
|
|
<script src="https://cdn.bootcdn.net/ajax/libs/jszip/3.1.5/jszip.min.js"></script>
|
|
|
|
|
<script src="https://cdn.jsdelivr.net/npm/epubjs@0.3.88/dist/epub.min.js"></script>
|
|
|
|
|
<script>
|
2021-09-29 08:07:22 +00:00
|
|
|
|
document.addEventListener('DOMContentLoaded', () => {
|
|
|
|
|
const html = document.querySelector('html')
|
|
|
|
|
let fontSize = window.innerWidth / 10
|
|
|
|
|
fontSize = fontSize > 50 ? 50 : fontSize
|
|
|
|
|
html.style.fontSize = fontSize + 'px'
|
|
|
|
|
})
|
2021-09-26 13:00:26 +00:00
|
|
|
|
</script>
|
|
|
|
|
<style>
|
2021-09-29 08:07:22 +00:00
|
|
|
|
* {
|
|
|
|
|
padding: 0;
|
|
|
|
|
margin: 0;
|
|
|
|
|
}
|
2021-10-03 09:05:31 +00:00
|
|
|
|
|
2021-09-29 08:07:22 +00:00
|
|
|
|
.mask {
|
|
|
|
|
position: absolute;
|
|
|
|
|
display: flex;
|
|
|
|
|
left: 0;
|
|
|
|
|
width: 100%;
|
|
|
|
|
height: 100%;
|
|
|
|
|
flex-direction: column;
|
|
|
|
|
}
|
2021-10-03 09:05:31 +00:00
|
|
|
|
|
2021-09-29 08:07:22 +00:00
|
|
|
|
.meun {
|
|
|
|
|
display: flex;
|
2021-09-30 06:38:49 +00:00
|
|
|
|
height: 1rem;
|
2021-09-29 08:07:22 +00:00
|
|
|
|
align-items: center;
|
|
|
|
|
}
|
2021-10-03 09:05:31 +00:00
|
|
|
|
|
|
|
|
|
#toc {
|
2021-09-29 08:07:22 +00:00
|
|
|
|
flex: 1;
|
|
|
|
|
z-index: 100;
|
2021-09-30 06:38:49 +00:00
|
|
|
|
font-size: .3rem;
|
|
|
|
|
padding-left: .4rem;
|
2021-09-29 08:07:22 +00:00
|
|
|
|
color: #333;
|
|
|
|
|
}
|
2021-10-03 09:05:31 +00:00
|
|
|
|
|
|
|
|
|
#page {
|
|
|
|
|
z-index: 100;
|
|
|
|
|
font-size: .3rem;
|
|
|
|
|
color: #333;
|
|
|
|
|
padding-right: 0.4rem;
|
|
|
|
|
text-align: right;
|
|
|
|
|
flex: 0 0 .5rem;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#load {
|
|
|
|
|
z-index: 100;
|
|
|
|
|
font-size: .3rem;
|
|
|
|
|
color: #333;
|
|
|
|
|
padding-right: 0.4rem;
|
|
|
|
|
text-align: right;
|
|
|
|
|
flex: 0 0 .5rem;
|
|
|
|
|
}
|
|
|
|
|
|
2021-09-29 08:07:22 +00:00
|
|
|
|
#toc-content {
|
|
|
|
|
position: absolute;
|
2021-09-30 06:38:49 +00:00
|
|
|
|
display: flex;
|
|
|
|
|
top: 0;
|
2021-09-29 08:07:22 +00:00
|
|
|
|
right: 0;
|
|
|
|
|
z-index: 102;
|
2021-09-30 06:38:49 +00:00
|
|
|
|
min-width: auto;
|
|
|
|
|
max-width: 80%;
|
2021-09-29 08:07:22 +00:00
|
|
|
|
height: 100%;
|
|
|
|
|
background: white;
|
2021-09-30 06:38:49 +00:00
|
|
|
|
flex-direction: column
|
2021-09-29 08:07:22 +00:00
|
|
|
|
}
|
2021-10-03 09:05:31 +00:00
|
|
|
|
|
2021-09-29 08:07:22 +00:00
|
|
|
|
#toc-mask {
|
|
|
|
|
position: absolute;
|
|
|
|
|
top: 0;
|
|
|
|
|
left: 0;
|
|
|
|
|
z-index: 101;
|
|
|
|
|
width: 100%;
|
|
|
|
|
height: 100%;
|
|
|
|
|
background: rgba(51, 51, 51, .8);
|
|
|
|
|
}
|
2021-10-03 09:05:31 +00:00
|
|
|
|
|
2021-09-30 06:38:49 +00:00
|
|
|
|
.intro {
|
2021-09-29 08:07:22 +00:00
|
|
|
|
width: 100%;
|
2021-09-30 06:38:49 +00:00
|
|
|
|
height: 2.4rem;
|
|
|
|
|
padding: .2rem .4rem;
|
|
|
|
|
box-sizing: border-box;
|
|
|
|
|
height: 3rem;
|
|
|
|
|
display: flex;
|
|
|
|
|
border-bottom: .1rem solid #f4f4f4;
|
|
|
|
|
}
|
2021-10-03 09:05:31 +00:00
|
|
|
|
|
2021-09-30 06:38:49 +00:00
|
|
|
|
.txt {
|
|
|
|
|
display: flex;
|
|
|
|
|
flex: 1;
|
|
|
|
|
align-items: center;
|
|
|
|
|
padding: 0 .2rem;
|
|
|
|
|
font-size: .3rem;
|
|
|
|
|
}
|
2021-10-03 09:05:31 +00:00
|
|
|
|
|
2021-09-30 06:38:49 +00:00
|
|
|
|
#content {
|
|
|
|
|
overflow-y: auto;
|
2021-09-29 08:07:22 +00:00
|
|
|
|
}
|
2021-10-03 09:05:31 +00:00
|
|
|
|
|
2021-09-29 08:07:22 +00:00
|
|
|
|
.item {
|
2021-09-30 06:38:49 +00:00
|
|
|
|
padding: .2rem .4rem;
|
|
|
|
|
border-bottom: .07rem solid #f4f4f4;
|
|
|
|
|
font-size: .4rem;
|
2021-09-29 08:07:22 +00:00
|
|
|
|
color: #333;
|
|
|
|
|
}
|
2021-10-03 09:05:31 +00:00
|
|
|
|
|
2021-09-29 08:07:22 +00:00
|
|
|
|
#open {
|
2021-09-30 06:38:49 +00:00
|
|
|
|
display: flex;
|
2021-09-29 08:07:22 +00:00
|
|
|
|
flex: 1;
|
|
|
|
|
z-index: 100;
|
2021-09-30 06:38:49 +00:00
|
|
|
|
font-size: .4rem;
|
2021-09-29 08:07:22 +00:00
|
|
|
|
color: #333;
|
2021-09-30 06:38:49 +00:00
|
|
|
|
align-items: flex-end;
|
|
|
|
|
justify-content: center;
|
2021-09-29 08:07:22 +00:00
|
|
|
|
|
2021-09-30 06:38:49 +00:00
|
|
|
|
}
|
2021-10-03 09:05:31 +00:00
|
|
|
|
|
2021-09-30 06:38:49 +00:00
|
|
|
|
#open span {
|
|
|
|
|
padding: .3rem .3rem;
|
|
|
|
|
border: .05rem solid #333;
|
|
|
|
|
border-radius: .2rem;
|
|
|
|
|
}
|
2021-10-03 09:05:31 +00:00
|
|
|
|
|
2021-09-29 08:07:22 +00:00
|
|
|
|
.read {
|
|
|
|
|
display: flex;
|
|
|
|
|
flex: 1 1 auto;
|
|
|
|
|
}
|
2021-10-03 09:05:31 +00:00
|
|
|
|
|
2021-09-29 08:07:22 +00:00
|
|
|
|
#prev {
|
2021-09-30 06:38:49 +00:00
|
|
|
|
flex: 0 0 2rem;
|
2021-09-29 08:07:22 +00:00
|
|
|
|
z-index: 100;
|
|
|
|
|
}
|
2021-10-03 09:05:31 +00:00
|
|
|
|
|
2021-09-29 08:07:22 +00:00
|
|
|
|
#viewer {
|
|
|
|
|
flex: 1;
|
|
|
|
|
}
|
2021-10-03 09:05:31 +00:00
|
|
|
|
|
2021-09-29 08:07:22 +00:00
|
|
|
|
#next {
|
2021-09-30 06:38:49 +00:00
|
|
|
|
flex: 0 0 2rem;
|
2021-09-29 08:07:22 +00:00
|
|
|
|
z-index: 100;
|
|
|
|
|
}
|
2021-10-03 09:05:31 +00:00
|
|
|
|
|
2021-09-30 06:38:49 +00:00
|
|
|
|
.save {
|
|
|
|
|
display: flex;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.box {
|
|
|
|
|
padding: .2rem .2rem;
|
|
|
|
|
justify-content: center;
|
|
|
|
|
border-bottom: .1rem solid #f4f4f4;
|
|
|
|
|
}
|
2021-10-03 09:05:31 +00:00
|
|
|
|
|
|
|
|
|
.jump {
|
|
|
|
|
display: flex;
|
|
|
|
|
height: 1rem;
|
|
|
|
|
border-bottom: .1rem solid #f4f4f4;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.jump input {
|
|
|
|
|
flex: 1;
|
|
|
|
|
padding: .1rem .1rem;
|
|
|
|
|
margin: .2rem .2rem .2rem .4rem;
|
|
|
|
|
outline: none;
|
|
|
|
|
font-size: .3rem;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.jump span {
|
|
|
|
|
flex: 0 0 1rem;
|
|
|
|
|
}
|
2021-09-26 13:00:26 +00:00
|
|
|
|
</style>
|
2021-09-29 08:07:22 +00:00
|
|
|
|
</head>
|
2021-10-03 09:05:31 +00:00
|
|
|
|
|
2021-09-29 08:07:22 +00:00
|
|
|
|
<body>
|
2021-09-26 13:00:26 +00:00
|
|
|
|
<div id="ebook">
|
2021-09-29 08:07:22 +00:00
|
|
|
|
<div class="mask">
|
2021-09-30 06:38:49 +00:00
|
|
|
|
<div id="open">
|
|
|
|
|
<span
|
|
|
|
|
onclick="document.getElementById('input').click();document.getElementById('open').style.display = 'none'">选择本地书籍</span>
|
|
|
|
|
<input type="file" id="input" style="display: none;">
|
|
|
|
|
</div>
|
2021-09-29 08:07:22 +00:00
|
|
|
|
<div class="read">
|
|
|
|
|
<div id="prev" onclick="rendition.prev()"></div>
|
|
|
|
|
<div id="viewer"></div>
|
|
|
|
|
<div id="next" onclick="rendition.next()"></div>
|
|
|
|
|
</div>
|
|
|
|
|
<div class="meun">
|
2021-09-30 06:38:49 +00:00
|
|
|
|
<div id="toc" onclick="showhide()"></div>
|
2021-10-03 09:05:31 +00:00
|
|
|
|
<div id="page"></div>
|
|
|
|
|
<div id="load"></div>
|
2021-09-29 08:07:22 +00:00
|
|
|
|
</div>
|
|
|
|
|
<div id="toc-mask" style="display: none;" onclick="showhide()"></div>
|
|
|
|
|
<div id="toc-content" style="display: none;">
|
2021-09-30 06:38:49 +00:00
|
|
|
|
<div class="intro">
|
|
|
|
|
<img id="cover">
|
|
|
|
|
<div style="display: flex;flex: 1;flex-direction: column;overflow-y: auto;">
|
|
|
|
|
<div id="title" class="txt"></div>
|
|
|
|
|
<div id="author" class="txt"></div>
|
|
|
|
|
<div id="publisher" class="txt"></div>
|
|
|
|
|
<div id="pubdate" class="txt"></div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
<div class="save">
|
|
|
|
|
<div class="txt box" onclick="save()">存档</div>
|
|
|
|
|
<div class="txt box" onclick="get()">读档</div>
|
|
|
|
|
<div class="txt box" onclick="del()">删档</div>
|
|
|
|
|
</div>
|
2021-10-03 09:05:31 +00:00
|
|
|
|
<div class="jump">
|
|
|
|
|
<input id="jump" type="number" placeholder="0-1之间的数字,如0.25"
|
|
|
|
|
oninput="if(value>1)value=1;if(value<0)value=0">
|
|
|
|
|
<span class="txt" onclick="jump()">跳转</span>
|
|
|
|
|
</div>
|
2021-09-29 08:07:22 +00:00
|
|
|
|
<div id="content"></div>
|
2021-09-26 13:00:26 +00:00
|
|
|
|
</div>
|
2021-09-29 08:07:22 +00:00
|
|
|
|
</div>
|
2021-09-26 13:00:26 +00:00
|
|
|
|
</div>
|
|
|
|
|
<script>
|
2021-09-29 08:07:22 +00:00
|
|
|
|
let url = location.search.substring(3);
|
|
|
|
|
if (url !== "") {
|
|
|
|
|
var book = ePub(url);
|
2021-09-30 06:38:49 +00:00
|
|
|
|
document.getElementById("open").style.display = "none"
|
2021-09-29 08:07:22 +00:00
|
|
|
|
} else {
|
|
|
|
|
var book = ePub();
|
|
|
|
|
var inputElement = document.getElementById("input");
|
|
|
|
|
inputElement.addEventListener('change', function (e) {
|
|
|
|
|
var file = e.target.files[0];
|
|
|
|
|
if (window.FileReader) {
|
|
|
|
|
var reader = new FileReader();
|
|
|
|
|
reader.onload = openBook;
|
|
|
|
|
reader.readAsArrayBuffer(file);
|
|
|
|
|
}
|
2021-09-26 13:00:26 +00:00
|
|
|
|
});
|
2021-09-29 08:07:22 +00:00
|
|
|
|
function openBook(e) {
|
|
|
|
|
var bookData = e.target.result;
|
|
|
|
|
book.open(bookData, "binary");
|
2021-09-26 13:00:26 +00:00
|
|
|
|
}
|
2021-09-29 08:07:22 +00:00
|
|
|
|
}
|
|
|
|
|
//渲染
|
|
|
|
|
var rendition = book.renderTo("ebook", {
|
|
|
|
|
with: window.innerWidth,
|
|
|
|
|
height: window.innerHeight - 20
|
|
|
|
|
});
|
|
|
|
|
rendition.display();
|
2021-10-03 09:05:31 +00:00
|
|
|
|
|
|
|
|
|
book.ready
|
|
|
|
|
.then(() => {
|
|
|
|
|
var local = localStorage.getItem(book.key() + '-locations');
|
|
|
|
|
if (local) {
|
|
|
|
|
return book.locations.load(local);
|
|
|
|
|
} else {
|
|
|
|
|
return book.locations.generate();
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
.then(locations => {
|
|
|
|
|
localStorage.setItem(book.key() + '-locations', book.locations.save());
|
|
|
|
|
})
|
|
|
|
|
|
2021-09-29 08:07:22 +00:00
|
|
|
|
// 目录
|
2021-10-03 09:05:31 +00:00
|
|
|
|
book.loaded.navigation.then(toc => {
|
|
|
|
|
var read = localStorage.getItem(book.key() + '-read');
|
|
|
|
|
if (read) {
|
|
|
|
|
rendition.display(read);
|
2021-09-30 06:38:49 +00:00
|
|
|
|
}
|
|
|
|
|
var $content = document.getElementById("content");
|
2021-10-03 09:05:31 +00:00
|
|
|
|
toc.forEach(item => {
|
2021-09-29 08:07:22 +00:00
|
|
|
|
var div = document.createElement("div");
|
|
|
|
|
div.className = "item";
|
2021-10-03 09:05:31 +00:00
|
|
|
|
div.textContent = item.label;
|
|
|
|
|
div.addEventListener("click", () => {
|
|
|
|
|
rendition.display(item.href);
|
2021-09-29 08:07:22 +00:00
|
|
|
|
showhide()
|
|
|
|
|
});
|
|
|
|
|
$content.appendChild(div)
|
2021-09-26 13:00:26 +00:00
|
|
|
|
})
|
2021-09-29 08:07:22 +00:00
|
|
|
|
})
|
2021-09-30 06:38:49 +00:00
|
|
|
|
//简介
|
2021-10-03 09:05:31 +00:00
|
|
|
|
book.loaded.metadata.then(meta => {
|
2021-09-30 06:38:49 +00:00
|
|
|
|
var $title = document.getElementById("title");
|
|
|
|
|
var $author = document.getElementById("author");
|
|
|
|
|
var $cover = document.getElementById("cover");
|
|
|
|
|
var $publisher = document.getElementById("publisher");
|
|
|
|
|
var $pubdate = document.getElementById("pubdate");
|
|
|
|
|
$title.textContent = `书名:${meta.title}`;
|
|
|
|
|
$author.textContent = `作者:${meta.creator}`;
|
|
|
|
|
$publisher.textContent = `出版社:${meta.publisher}`;
|
|
|
|
|
$pubdate.textContent = `时间:${meta.pubdate}`;
|
|
|
|
|
if (book.archive) {
|
|
|
|
|
book.archive.createUrl(book.cover)
|
2021-10-03 09:05:31 +00:00
|
|
|
|
.then(url => {
|
2021-09-30 06:38:49 +00:00
|
|
|
|
$cover.src = url;
|
|
|
|
|
})
|
|
|
|
|
} else {
|
|
|
|
|
$cover.src = book.cover;
|
|
|
|
|
}
|
|
|
|
|
});
|
2021-10-03 09:05:31 +00:00
|
|
|
|
//进度显示
|
|
|
|
|
rendition.on('relocated', location => {
|
|
|
|
|
var percent = book.locations.percentageFromCfi(location.start.cfi);
|
2021-09-30 06:38:49 +00:00
|
|
|
|
var $page = document.getElementById("page");
|
2021-10-03 09:05:31 +00:00
|
|
|
|
var $load = document.getElementById("load");
|
2021-09-30 06:38:49 +00:00
|
|
|
|
$page.textContent = location.end.displayed.page + '/' + location.end.displayed.total;
|
2021-10-03 09:05:31 +00:00
|
|
|
|
$load.textContent = Math.fround(percent * 100).toFixed(1) + '%';
|
2021-09-30 06:38:49 +00:00
|
|
|
|
})
|
2021-10-03 09:05:31 +00:00
|
|
|
|
//章节名显示
|
|
|
|
|
rendition.on("rendered", section => {
|
2021-09-30 06:38:49 +00:00
|
|
|
|
var $toc = document.getElementById("toc");
|
|
|
|
|
$toc.textContent = "目录";
|
|
|
|
|
$toc.textContent = book.navigation.get(section.href).label;
|
|
|
|
|
})
|
|
|
|
|
function showhide() {
|
|
|
|
|
var $toc_content = document.getElementById("toc-content")
|
|
|
|
|
var $mask = document.getElementById("toc-mask")
|
|
|
|
|
if ($toc_content.style.display == "none") {
|
|
|
|
|
$toc_content.style.display = ""
|
|
|
|
|
$mask.style.display = ""
|
|
|
|
|
} else {
|
|
|
|
|
$toc_content.style.display = "none"
|
|
|
|
|
$mask.style.display = "none"
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-10-03 09:05:31 +00:00
|
|
|
|
function jump() {
|
|
|
|
|
$jump = document.getElementById("jump").value;
|
|
|
|
|
rendition.display(book.locations.cfiFromPercentage($jump));
|
|
|
|
|
showhide();
|
|
|
|
|
document.getElementById("jump").value = "";
|
|
|
|
|
}
|
2021-09-30 06:38:49 +00:00
|
|
|
|
function save() {
|
2021-10-03 09:05:31 +00:00
|
|
|
|
localStorage.setItem(book.key() + '-read', rendition.currentLocation().start.cfi)
|
2021-09-30 06:38:49 +00:00
|
|
|
|
showhide()
|
|
|
|
|
}
|
|
|
|
|
function get() {
|
2021-10-03 09:05:31 +00:00
|
|
|
|
rendition.display(localStorage.getItem(book.key() + '-read'));
|
2021-09-30 06:38:49 +00:00
|
|
|
|
showhide()
|
|
|
|
|
}
|
|
|
|
|
function del() {
|
2021-10-03 09:05:31 +00:00
|
|
|
|
localStorage.removeItem(book.key() + '-read');
|
2021-09-30 06:38:49 +00:00
|
|
|
|
showhide()
|
|
|
|
|
}
|
2021-09-26 13:00:26 +00:00
|
|
|
|
</script>
|
2021-09-29 08:07:22 +00:00
|
|
|
|
</body>
|
2021-10-03 09:05:31 +00:00
|
|
|
|
|
2021-09-26 13:00:26 +00:00
|
|
|
|
</html>
|