7 content=
"width=device-width,initial-scale=1.0,maximum-scale=1.0,minimum-scale=1.0,user-scalable=no">
9 <script src=
"https://cdn.bootcdn.net/ajax/libs/jszip/3.1.5/jszip.min.js"></script>
10 <script src=
"https://fastly.jsdelivr.net/npm/epubjs@0.3.88/dist/epub.min.js"></script>
12 document
.addEventListener('DOMContentLoaded', () => {
13 const html
= document
.querySelector('html')
14 let fontSize
= window
.innerWidth
/ 10
15 fontSize
= fontSize
> 50 ? 50 : fontSize
16 html
.style
.fontSize
= fontSize
+ 'px'
31 flex-direction: column;
52 padding-right:
0.4rem;
61 padding-right:
0.4rem;
76 flex-direction: column
86 background: rgba(
51,
51,
51,
.8);
93 box-sizing: border-box;
96 border-bottom:
.1rem solid #f4f4f4;
112 padding:
.2rem
.4rem;
113 border-bottom:
.07rem solid #f4f4f4;
124 align-items: flex-end;
125 justify-content: center;
130 padding:
.3rem
.3rem;
131 border:
.05rem solid #
333;
132 border-radius:
.2rem;
159 padding:
.2rem
.2rem;
160 justify-content: center;
161 border-bottom:
.1rem solid #f4f4f4;
167 border-bottom:
.1rem solid #f4f4f4;
172 padding:
.1rem
.1rem;
173 margin:
.2rem
.2rem
.2rem
.4rem;
189 onclick=
"document.getElementById('input').click();document.getElementById('open').style.display = 'none'">选择本地书籍
</span>
190 <input type=
"file" id=
"input" style=
"display: none;">
193 <div id=
"prev" onclick=
"rendition.prev()"></div>
194 <div id=
"viewer"></div>
195 <div id=
"next" onclick=
"rendition.next()"></div>
198 <div id=
"toc" onclick=
"showhide()"></div>
199 <div id=
"page"></div>
200 <div id=
"load"></div>
202 <div id=
"toc-mask" style=
"display: none;" onclick=
"showhide()"></div>
203 <div id=
"toc-content" style=
"display: none;">
206 <div style=
"display: flex;flex: 1;flex-direction: column;overflow-y: auto;">
207 <div id=
"title" class=
"txt"></div>
208 <div id=
"author" class=
"txt"></div>
209 <div id=
"publisher" class=
"txt"></div>
210 <div id=
"pubdate" class=
"txt"></div>
214 <div class=
"txt box" onclick=
"save()">存档
</div>
215 <div class=
"txt box" onclick=
"get()">读档
</div>
216 <div class=
"txt box" onclick=
"del()">删档
</div>
219 <input id=
"jump" type=
"number" placeholder=
"0-1之间的数字,如0.25"
220 oninput=
"if(value>1)value=1;if(value<0)value=0">
221 <span class=
"txt" onclick=
"jump()">跳转
</span>
223 <div id=
"content"></div>
228 let url
= location
.search
.substring(3);
230 var book
= ePub(url
);
231 document
.getElementById("open").style
.display
= "none"
234 var inputElement
= document
.getElementById("input");
235 inputElement
.addEventListener('change', function (e
) {
236 var file
= e
.target
.files
[0];
237 if (window
.FileReader
) {
238 var reader
= new FileReader();
239 reader
.onload
= openBook
;
240 reader
.readAsArrayBuffer(file
);
243 function openBook(e
) {
244 var bookData
= e
.target
.result
;
245 book
.open(bookData
, "binary");
249 var rendition
= book
.renderTo("ebook", {
250 with: window
.innerWidth
,
251 height
: window
.innerHeight
- 20
257 var local
= localStorage
.getItem(book
.key() + '-locations');
259 return book
.locations
.load(local
);
261 return book
.locations
.generate();
265 localStorage
.setItem(book
.key() + '-locations', book
.locations
.save());
269 book
.loaded
.navigation
.then(toc
=> {
270 var read
= localStorage
.getItem(book
.key() + '-read');
272 rendition
.display(read
);
274 var $content
= document
.getElementById("content");
275 toc
.forEach(item
=> {
276 var div
= document
.createElement("div");
277 div
.className
= "item";
278 div
.textContent
= item
.label
;
279 div
.addEventListener("click", () => {
280 rendition
.display(item
.href
);
283 $content
.appendChild(div
)
287 book
.loaded
.metadata
.then(meta
=> {
288 var $title
= document
.getElementById("title");
289 var $author
= document
.getElementById("author");
290 var $cover
= document
.getElementById("cover");
291 var $publisher
= document
.getElementById("publisher");
292 var $pubdate
= document
.getElementById("pubdate");
293 $title
.textContent
= `书名:${meta.title}`;
294 $author
.textContent
= `作者:${meta.creator}`;
295 $publisher
.textContent
= `出版社:${meta.publisher}`;
296 $pubdate
.textContent
= `时间:${meta.pubdate}`;
298 book
.archive
.createUrl(book
.cover
)
303 $cover
.src
= book
.cover
;
307 rendition
.on('relocated', location
=> {
308 var percent
= book
.locations
.percentageFromCfi(location
.start
.cfi
);
309 var $page
= document
.getElementById("page");
310 var $load
= document
.getElementById("load");
311 $page
.textContent
= location
.end
.displayed
.page
+ '/' + location
.end
.displayed
.total
;
312 $load
.textContent
= Math
.fround(percent
* 100).toFixed(1) + '%';
315 rendition
.on("rendered", section
=> {
316 var $toc
= document
.getElementById("toc");
317 $toc
.textContent
= "目录";
318 $toc
.textContent
= book
.navigation
.get(section
.href
).label
;
320 function showhide() {
321 var $toc_content
= document
.getElementById("toc-content")
322 var $mask
= document
.getElementById("toc-mask")
323 if ($toc_content
.style
.display
== "none") {
324 $toc_content
.style
.display
= ""
325 $mask
.style
.display
= ""
327 $toc_content
.style
.display
= "none"
328 $mask
.style
.display
= "none"
332 $jump
= document
.getElementById("jump").value
;
333 rendition
.display(book
.locations
.cfiFromPercentage($jump
));
335 document
.getElementById("jump").value
= "";
338 localStorage
.setItem(book
.key() + '-read', rendition
.currentLocation().start
.cfi
)
342 rendition
.display(localStorage
.getItem(book
.key() + '-read'));
346 localStorage
.removeItem(book
.key() + '-read');