-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
383 lines (343 loc) · 13.1 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<script src="meta.js"></script>
<script>
let metaData = ''
let rootPath = ''
let title = ''
let bookInfo = ''
let pages = []
let map = {}
let cover = ''
let funImages = []
class Page {
id = ''
path = ''
title = ''
}
let userPath = []
let userPathMark = 0
function getCleanPath(path) {
path = path + ""
if (path.indexOf('#') >= 0) {
path = path.substring(0, path.indexOf('#'))
}
if (path.indexOf('?') >= 0) {
path = path.substring(0, path.indexOf('?'))
}
let parts = (path + '').split('/')
console.log(parts)
let npath = ''
for (let i in parts) {
if (parts[i] === '') {
continue
}
npath += parts[i] + (i < parts.length - 1 ? '/' : '')
}
return npath
}
function fixEle(es, attr, click) {
for (let i in es) {
let a = es[i]
if (a[attr]) {
let path = a[attr] + ""
let mask = window.location.protocol + '//' + window.location.host
if (path.indexOf(mask) < 0 && (path.indexOf('http://') >= 0 || path.indexOf('https://') >= 0)) {
continue
}
if (path.indexOf(mask) >= 0) {
path = path.substring(path.indexOf(mask) + mask.length, path.length)
}
a[attr] = rootPath + path
a.className += 'flink'
if (click) {
a.addEventListener('click', (ev) => {
ev.preventDefault()
openPage(rootPath + path)
})
}
}
}
}
function openPage(path, move = false) {
let moveHis = function (path, move) {
if (!move) {
if (userPath.length <= 0) {
userPath.push(path)
} else {
if (userPathMark + 1 >= userPath.length) {
userPath.push(path)
userPathMark = userPath.length - 1
} else {
userPath[userPathMark + 1] = path
userPathMark += 1
userPath.splice(userPathMark + 1, userPath.length - userPathMark - 1)
}
}
}
}
if (path === '') {
toHome()
moveHis(path, move)
return
}
let box = document.getElementById('pageBox')
let xml = new XMLHttpRequest()
xml.addEventListener('load', (ev) => {
let data = document.createElement('div')
data.innerHTML = xml.responseText
fixEle(data.getElementsByTagName('a'), 'href', true)
fixEle(data.getElementsByTagName('img'), 'src', false)
fixEle(data.getElementsByTagName('image'), 'href', false)
fixEle(data.getElementsByTagName('image'), 'xlink:href', false)
fixEle(data.getElementsByTagName('link'), 'href', false)
box.innerHTML = ""
box.appendChild(data)
moveHis(path, move)
console.log(userPath)
console.log(userPathMark)
box.scrollIntoView(true)
})
xml.open('GET', path)
xml.send()
}
function goBack() {
if (userPathMark > 0) {
userPathMark -= 1
openPage(userPath[userPathMark], true)
}
}
function goAhead() {
if (userPathMark + 1 < userPath.length) {
userPathMark += 1
openPage(userPath[userPathMark], true)
}
}
function refresh() {
openPage(userPath[userPathMark], true)
}
function toHome() {
document.getElementById('pageBox').innerHTML = bookInfo
}
function toPrevious() {
let indice = map[getCleanPath(userPath[userPathMark])]
console.log(indice, pages.length, getCleanPath(userPath[userPathMark]))
if (indice > 0) {
openPage(pages[indice - 1].path)
}
}
function toNext() {
let indice = map[getCleanPath(userPath[userPathMark])]
console.log(indice, pages.length, getCleanPath(userPath[userPathMark]))
if (indice < pages.length - 1) {
openPage(pages[indice + 1].path)
}
}
</script>
<style>
#table {
position: fixed;
left: -180pt;
top: 10%;
z-index: 10;
width: 200pt;
height: 80%;
overflow: auto;
transition: all 1s 0s ease;
background: #EAEAEA;
border-radius: 0px;
padding: 14pt;
box-sizing: border-box;
}
#table:hover {
left: 0pt;
}
#pageBox {
width: 100%;
padding: 84pt 156pt;
box-sizing: border-box;
}
.flink {
color: darkblue;
cursor: pointer;
}
.flink:hover {
color: darkorchid;
}
.flink:visited {
color: darkolivegreen;
}
.item {
padding: 12pt 2pt;
box-sizing: border-box;
text-align: left;
font-size: medium;
font-style: normal;
font-weight: normal;
font-family: 'Courier New', Courier, monospace;
line-height: normal;
text-indent: 0em;
}
.toolbar {
position: fixed;
right: 5pt;
top: 5pt;
background: #EAEAEA;
width: 26pt;
padding: 0pt 0pt 3pt 0pt;
border-radius: 5px;
z-index: 10;
}
.toolbar button {
width: 80%;
font-size: 12pt;
margin: 3pt auto 0pt auto;
box-sizing: border-box;
display: block;
border: none;
background: #FFF;
font-weight: bold;
text-align: center;
border-radius: 5px;
cursor: pointer;
}
.toolbar button:hover {
background: #BBB;
}
.turnPage {
margin: 16pt 2pt;
border: none;
border-radius: 5px;
background: #EEE;
color: #121212;
padding: 3pt 6pt;
cursor: pointer;
border: solid 5px #FFF;
box-sizing: border-box;
}
.turnPage:hover {
background: #CCC;
}
.indentXXX {
margin-left: 156pt;
}
.guideBar {
position: fixed;
left: 0px;
top: 0pt;
padding: 0pt;
color: black;
font-size: medium;
text-indent: 0cm;
z-index: 10;
}
body {
padding: 0pt;
background: #FFF;
color: black;
overflow-y: scroll;
font-size: medium;
text-indent: 0cm;
}
.title {
font-size: 24pt;
word-wrap: break-word;
}
.cover {
width: 60%;
}
.outline {
width: 10%;
margin: 4pt;
}
</style>
</head>
<body>
<div id="table">
</div>
<div class="guideBar">
<button onclick="toPrevious()" class="turnPage indentXXX">Previous</button>
<button onclick="toNext()" class="turnPage">Next</button>
</div>
<div id="pageBox">
</div>
<div class="toolbar">
<button onclick="goBack()">◀️</button>
<button onclick="goAhead()">▶️</button>
<button onclick="refresh()">🔁</button>
<button onclick="openPage('')">🏠</button>
</div>
<script>
function renderBook() {
let parse = new DOMParser()
let xdom = parse.parseFromString(metaData, 'text/xml')
pages = []
let home = new Page()
home.id = 'Info'
home.path = ''
home.title = 'Info'
pages.push(home)
map = { '': 0 }
cover = ''
funImages = []
title = xdom.getElementsByTagName('dc:title')[0].innerHTML
bookInfo = '<div class="title">' + title + '</div>'
let items = xdom.getElementsByTagName('item')
for (let i = 0; i < items.length; i++) {
if (items[i].getAttribute('id')) {
if (items[i].getAttribute('id') === 'Cover' || items[i].getAttribute('id') === 'cover') {
cover = rootPath + items[i].getAttribute('href')
} else if (cover.length == 0 && items[i].getAttribute('media-type') && items[i].getAttribute('media-type').indexOf('image') >= 0) {
cover = rootPath + items[i].getAttribute('href')
} else if (cover.length != 0 && items[i].getAttribute('media-type') && items[i].getAttribute('media-type').indexOf('image') >= 0) {
funImages.push(rootPath + items[i].getAttribute('href'))
}
}
if (!items[i].hasAttribute('media-type') || items[i].getAttribute('media-type').indexOf('html') >= 0) {
let page = new Page();
page.id = items[i].getAttribute('id')
page.path = rootPath + items[i].getAttribute('href')
pages.push(page)
map[getCleanPath(page.path)] = pages.length - 1
}
}
if (cover.length > 0) {
bookInfo += '<br /><img class="cover" src="' + cover + '" />'
}
if (funImages.length > 0) {
for (let i in funImages) {
bookInfo += '<img class="outline" src="' + funImages[i] + '" />'
}
}
let refs = xdom.getElementsByTagName('reference')
for (let i = 0; i < refs.length; i++) {
console.log(refs[i])
let path = rootPath + refs[i].getAttribute('href')
console.log(getCleanPath(path), map[getCleanPath(path)])
if (map[getCleanPath(path)]) {
pages[map[getCleanPath(path)]].title = refs[i].getAttribute('title')
}
}
for (let i in pages) {
let table = document.getElementById('table')
let item = document.createElement('div')
let call = 'openPage(\'' + pages[i].path + '\')'
item.innerHTML = '<div class="flink item" onclick="' + call + '">' + (pages[i].title.length > 0 ? pages[i].title : pages[i].id) + '</div>'
table.append(item)
}
console.log(map)
openPage('')
}
let xml = new XMLHttpRequest()
xml.addEventListener('load', (ev) => {
metaData = xml.responseText
renderBook()
})
xml.open('GET', meta.metaPath)
rootPath = (meta.metaPath + '').substring(0, (meta.metaPath + '').lastIndexOf('/') + 1)
xml.send()
</script>
</body>
</html>