-
Notifications
You must be signed in to change notification settings - Fork 33
Expand file tree
/
Copy pathweb.html
More file actions
2270 lines (2016 loc) · 74.8 KB
/
web.html
File metadata and controls
2270 lines (2016 loc) · 74.8 KB
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
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="referrer" content="no-referrer" />
<title>小说搜索与下载</title>
<script id="FileSaver.js" src="https://s4.zstatic.net/ajax/libs/FileSaver.js/2.0.5/FileSaver.min.js"></script>
<!-- 自己把下面两行取消注释可用移动端开发者工具 -->
<script>
if (typeof navigator !== 'undefined' && navigator.userAgent.match(/Android|iOS/) && window.location.href.includes('dev=true')) {
const script = document.createElement('script')
script.src = 'https://s4.zstatic.net/ajax/libs/eruda/3.4.1/eruda.min.js'
script.referrerpolicy = 'no-referrer'
script.crossorigin = 'anonymous'
script.id = 'eruda.js'
document.head.appendChild(script)
const intv = setInterval(() => {
try {
eruda.init()
clearInterval(intv)
} catch (e) {}
}, 500)
}
</script>
<script id="moment.js" src="https://s4.zstatic.net/ajax/libs/moment.js/2.30.1/moment.min.js"></script>
<script id="lodash.js" src="https://s4.zstatic.net/ajax/libs/lodash.js/4.17.21/lodash.min.js"></script>
<script
id="jszip"
src="https://s4.zstatic.net/ajax/libs/jszip/3.10.1/jszip.min.js"
integrity="sha512-XMVd28F1oH/O71fzwBnV7HucLxVwtxf26XV8P4wPk26EDxuGZ91N8bsOttmnomcCD3CS5ZMRL50H0GgOHvegtg=="
crossorigin="anonymous"
referrerpolicy="no-referrer"
></script>
<script id="gbk.js">
// 本来是压缩过的,结果格式化工具又给我格式化了,干脆不管了
'use strict'
let table
function initGbkTable() {
var r,
t,
e,
o,
n = new Uint16Array(23940)
let f = 0
for ([r, t, e, o] of [
[161, 169, 161, 254],
[176, 247, 161, 254],
[129, 160, 64, 254],
[170, 254, 64, 160],
[168, 169, 64, 160],
[170, 175, 161, 254],
[248, 254, 161, 254],
[161, 167, 64, 160],
])
for (let l = e; l <= o; l++) if (127 !== l) for (let e = r; e <= t; e++) n[f++] = (l << 8) | e
;(table = new Uint16Array(65536)).fill(65535)
var l = new TextDecoder('gbk').decode(n)
for (let e = 0; e < l.length; e++) table[l.charCodeAt(e)] = n[e]
}
const NodeJsBufAlloc = 'function' == typeof globalThis.Buffer && Buffer.allocUnsafe,
defaultOnAlloc = NodeJsBufAlloc ? (e) => NodeJsBufAlloc(e) : (e) => new Uint8Array(e),
defaultOnError = () => 63
window.encodeGBK = function (l, e = {}) {
table || initGbkTable()
var r = e.onAlloc || defaultOnAlloc,
t = e.onError || defaultOnError,
o = r(2 * l.length)
let n = 0
for (let e = 0; e < l.length; e++) {
var f = l.charCodeAt(e)
if (f < 128) o[n++] = f
else {
var a = table[f]
if (65535 !== a) (o[n++] = a), (o[n++] = a >> 8)
else if (8364 === f) o[n++] = 128
else {
a = t(e, l)
if (-1 === a) break
255 < a ? ((o[n++] = a), (o[n++] = a >> 8)) : (o[n++] = a)
}
}
}
return o.subarray(0, n)
}
</script>
<script id="epub-saver.js" src="llepub-latest.js"></script>
</head>
<body>
<button class="toggle-theme" onclick="toggleTheme()">
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" id="light">
<circle cx="12" cy="12" r="10" fill="currentColor" />
</svg>
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" id="dark">
<path
fill="currentColor"
d="M10 2c-1.82 0-3.53.5-5 1.35C7.99 5.08 10 8.3 10 12s-2.01 6.92-5 8.65C6.47 21.5 8.18 22 10 22c5.52 0 10-4.48 10-10S15.52 2 10 2"
/>
</svg>
</button>
<h1 id="title">小说搜索与下载</h1>
<div id="container" class="container">
<form class="search-form" id="search-form">
<select id="search-type" class="search-type">
<option value="book">书籍</option>
<option value="audio">听书</option>
</select>
<input type="text" id="book-search" placeholder="请输入小说名称" />
<button type="button" onclick="searchBooks()">
<svg xmlns="http://www.w3.org/2000/svg" fill="currentColor" width="24" height="24" viewBox="0 0 24 24" display="inherit">
<path d="M16.296 16.996a8 8 0 11.707-.708l3.909 3.91-.707.707-3.909-3.909zM18 11a7 7 0 00-14 0 7 7 0 1014 0z" />
</svg>
</button>
</form>
<div id="book-list" class="book-list"></div>
<div id="book-info" class="book-info">
<img src="" alt="封面" id="book-cover" />
<div class="book-info-container">
<p id="book_id" style="display: none"></p>
<p id="book_info" style="display: none"></p>
<p id="download_lock" style="display: none"></p>
<h2 id="book-title"></h2>
<p><strong>作者:</strong><span id="book-author"></span></p>
<p><strong>分类:</strong><span id="book-category"></span></p>
<p><strong>状态:</strong><span id="creation-status"></span></p>
<p><strong>最新章节:</strong><span id="latest-chapter"></span> <span id="latest-chapter-passtime"></span></p>
<p id="book-description"></p>
<button class="download-btn" onclick="downloadBook()">下载</button>
<select id="type-selector" class="charset-selector">
<option value="text">文本</option>
<option value="audio">音频</option>
</select>
<select id="charset-selector" class="charset-selector">
<option value="utf-8">UTF-8</option>
<option value="gbk">GBK</option>
</select>
<select id="format-selector" class="charset-selector">
<option value="txt">TXT</option>
<option value="epub">EPUB</option>
</select>
</div>
</div>
</div>
<!-- 进度条弹窗 -->
<div id="progress-modal" class="progress-modal" style="display: none">
<div class="progress-box">
<h3 id="progress-title" class="progress-title">下载进度</h3>
<div class="progress-bar">
<div id="progress-bar-fill" class="progress-bar-fill"></div>
</div>
<div class="progress-text">
<p id="progress-percentage">0%</p>
<p id="progress-count">0/0</p>
</div>
<div id="sub-progress" style="display: none">
<div class="progress-bar">
<div id="sub-progress-bar-fill" class="progress-bar-fill"></div>
</div>
<p id="sub-progress-title" class="progress-text">副标题</p>
</div>
<button id="progress-cancel" class="progress-cancel">取消</button>
<button id="progress-submit" class="progress-submit" style="display: none">确定</button>
<button id="button-resave" class="button-resave" style="display: none" onclick="reSave()">手动保存</button>
<button id="button-redownload" class="button-redownload" style="display: none" onclick="reDownload()">重新下载</button>
</div>
</div>
<!-- 点击书名后的弹窗 -->
<dialog id="internal-alert" class="internal-alert">
<div id="internal-alert-container" class="internal-alert-container">
<span>内容</span>
</div>
</dialog>
<hr />
<div class="float-log-window" id="floatLogWindow">
<div class="float-log-header" onclick="toggleLogWindow()">
<span>执行日志</span>
<span class="toggle-icon" id="toggleIcon">▼</span>
</div>
<div class="float-log-content" id="logContent"></div>
</div>
<div class="footer">
<div class="about-container">
<p class="about-text">本网页为 <a href="https://github.com/MeoProject/PyFQWeb">PyFQWeb</a> 项目的一部分,请遵守开源协议使用</p>
</div>
</div>
<script>
const apiNode = 'https://ikun.laoguantx.top:4390'
if (!apiNode) alert('请配置apiNode后再使用网页(需要支持跨域)')
// 浮窗日志功能
let logCollapsed = false
let originalConsole = {}
// 检测是否为dev模式
function checkDevMode() {
// 检测eruda是否已加载
if (window.eruda) {
return true
}
// 检测eruda脚本标签
if (document.querySelector('script[id="eruda.js"]') || document.querySelector('script[src*="eruda"]')) {
return true
}
// 检测URL参数中是否包含dev=true
const urlParams = new URLSearchParams(window.location.search)
return urlParams.get('dev') === 'true'
}
// 初始化浮窗显示状态
function initFloatWindow() {
const floatWindow = document.getElementById('floatLogWindow')
if (!floatWindow) return
if (checkDevMode()) {
floatWindow.classList.add('hidden')
addLog('检测到开发模式,隐藏浮窗日志', 'info')
} else {
floatWindow.classList.remove('hidden')
addLog('非开发模式,显示浮窗日志', 'info')
}
}
// 切换日志窗口展开/收起
function toggleLogWindow() {
const logContent = document.getElementById('logContent')
const toggleIcon = document.getElementById('toggleIcon')
if (!logContent || !toggleIcon) return
logCollapsed = !logCollapsed
if (logCollapsed) {
logContent.classList.add('collapsed')
toggleIcon.classList.add('collapsed')
toggleIcon.textContent = '▲'
} else {
logContent.classList.remove('collapsed')
toggleIcon.classList.remove('collapsed')
toggleIcon.textContent = '▼'
}
}
// 添加日志
function addLog(message, level = 'info') {
const logContent = document.getElementById('logContent')
if (!logContent) return
const now = new Date()
const timeStr = now.toLocaleString('zh-CN', {
year: 'numeric',
month: '2-digit',
day: '2-digit',
hour: '2-digit',
minute: '2-digit',
second: '2-digit',
})
const logItem = document.createElement('div')
logItem.className = 'log-item'
logItem.innerHTML = `
<span class="log-time">[${timeStr}]</span>
<span class="log-message log-level-${level}">${message}</span>
`
logContent.appendChild(logItem)
// 自动滚动到底部
logContent.scrollTop = logContent.scrollHeight
// 限制日志条数,避免占用过多内存
const logItems = logContent.querySelectorAll('.log-item')
if (logItems.length > 100) {
logItems[0].remove()
}
}
// 覆写console方法来捕获日志
function setupConsoleCapture() {
if (checkDevMode()) return // dev模式下不捕获
// 保存原始console方法
originalConsole.log = console.log
originalConsole.warn = console.warn
originalConsole.error = console.error
originalConsole.info = console.info
// 覆写console.log
console.log = function (...args) {
originalConsole.log.apply(console, args)
addLog(args.join(' '), 'info')
}
// 覆写console.warn
console.warn = function (...args) {
originalConsole.warn.apply(console, args)
addLog(args.join(' '), 'warning')
}
// 覆写console.error
console.error = function (...args) {
originalConsole.error.apply(console, args)
addLog(args.join(' '), 'error')
}
// 覆写console.info
console.info = function (...args) {
originalConsole.info.apply(console, args)
addLog(args.join(' '), 'info')
}
}
// 定期检测dev模式变化
function watchDevModeChange() {
setInterval(() => {
const currentDevMode = checkDevMode()
const floatWindow = document.getElementById('floatLogWindow')
if (!floatWindow) return
const isHidden = floatWindow.classList.contains('hidden')
if (currentDevMode && !isHidden) {
floatWindow.classList.add('hidden')
// addLog('切换到开发模式,隐藏浮窗', 'warning');
} else if (!currentDevMode && isHidden) {
floatWindow.classList.remove('hidden')
// addLog('退出开发模式,显示浮窗', 'info');
}
}, 3000)
}
// TODO: 标准化API响应数据
function normalizeApiResponse(response) {
return response
}
function sleep(ms) {
return new Promise((resolve) => setTimeout(resolve, ms))
}
function btoaEh(str) {
const bytes = new TextEncoder().encode(str)
let binary = ''
bytes.forEach((b) => (binary += String.fromCharCode(b)))
return btoa(binary)
}
// URL参数管理函数
function updateUrlParams(params) {
const url = new URL(window.location.href)
if (url.protocol === 'file:' || url.protocol === 'content:') return
// 清除所有相关参数
url.searchParams.delete('book_id')
url.searchParams.delete('text')
url.searchParams.delete('search_type')
// 设置新参数
Object.keys(params).forEach((key) => {
if (params[key] !== null && params[key] !== undefined && params[key] !== '') {
url.searchParams.set(key, params[key])
}
})
// 更新URL而不刷新页面
window.history.pushState({ path: url.href }, '', url.href)
}
// 从URL参数恢复状态
function restoreFromUrlParams() {
const url = new URL(window.location.href)
const bookId = url.searchParams.get('book_id')
const searchText = url.searchParams.get('text')
const searchType = url.searchParams.get('search_type')
// 恢复搜索类型
if (searchType) {
const searchTypeSelect = document.getElementById('search-type')
if (searchTypeSelect) {
searchTypeSelect.value = searchType
}
}
// 恢复搜索框内容
if (searchText && !bookId) {
const searchInput = document.getElementById('book-search')
if (searchInput) {
searchInput.value = searchText
}
}
// 自动执行搜索或显示书籍信息
if (bookId) {
// 如果有book_id,直接显示书籍信息
showBookInfo(bookId)
} else if (searchText) {
// 如果只有搜索文本,执行搜索
searchBooks(searchText)
}
}
// 设置页面主题
function setTheme(theme) {
document.body.dataset.theme = theme
document.getElementById(theme).setAttribute('display', 'block')
document.getElementById(theme === 'dark' ? 'light' : 'dark').setAttribute('display', 'none')
}
// 自动检测浏览器主题并设置页面主题
function setThemeBasedOnPreference() {
const savedTheme = localStorage.getItem('theme')
if (savedTheme) {
setTheme(savedTheme)
} else {
const systemTheme = window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light'
setTheme(systemTheme)
}
}
// 切换主题并保存到localStorage
function toggleTheme() {
const currentTheme = document.body.dataset.theme || 'light'
const newTheme = currentTheme === 'dark' ? 'light' : 'dark'
setTheme(newTheme)
localStorage.setItem('theme', newTheme)
}
// 初始化主题
setThemeBasedOnPreference()
// 初始化form提交事件
document.getElementById('search-form').addEventListener('submit', function (event) {
event.preventDefault()
searchBooks()
})
function formatCount(num, lang) {
const units = {
zh: [
{ d: 1e8, s: '亿' },
{ d: 1e4, s: '万' },
],
en: [
{ d: 1e9, s: 'billion' },
{ d: 1e6, s: 'million' },
{ d: 1e3, s: 'thousand' },
],
ja: [
{ d: 1e8, s: '億' },
{ d: 1e4, s: '万' },
],
ko: [
{ d: 1e8, s: '억' },
{ d: 1e4, s: '만' },
],
de: [
{ d: 1e9, s: 'Milliarde' },
{ d: 1e6, s: 'Million' },
{ d: 1e3, s: 'Tausend' },
],
es: [
{ d: 1e9, s: 'mil millones' },
{ d: 1e6, s: 'millón' },
{ d: 1e3, s: 'mil' },
],
ru: [
{ d: 1e9, s: 'миллиард' },
{ d: 1e6, s: 'миллион' },
{ d: 1e3, s: 'тысяча' },
],
ar: [
{ d: 1e9, s: 'مليار' },
{ d: 1e6, s: 'مليون' },
{ d: 1e3, s: 'ألف' },
],
}
const browserLang = (navigator.language || 'en').substring(0, 2)
const targetLang = units[lang] ? lang : units[browserLang] ? browserLang : 'en'
const unit = units[targetLang].find((u) => num >= u.d) || { d: 1, s: '' }
const value = num / unit.d
const formatted = value
.toLocaleString(targetLang, {
maximumFractionDigits: 3,
minimumFractionDigits: 0,
})
.replace(/\.0+$/, '')
return targetLang === 'ar' ? `${formatted}\u202C${unit.s}\u202C` : `${formatted}${unit.s}`
}
function formatDuration(seconds) {
// 处理负数边界情况
const totalSeconds = Math.max(0, Math.round(seconds))
// 时间单位分解
const hours = Math.floor(totalSeconds / 3600)
const remaining = totalSeconds % 3600
const minutes = Math.floor(remaining / 60)
const secs = remaining % 60
// 构建时间片段
const timeFragments = []
if (hours > 0) {
timeFragments.push(hours.toString().padStart(2, '0'), minutes.toString().padStart(2, '0'))
} else {
timeFragments.push(minutes.toString().padStart(2, '0'))
}
timeFragments.push(secs.toString().padStart(2, '0'))
return timeFragments.join(':')
}
function isShitBrowser() {
const userAgent = navigator.userAgent.toLowerCase()
return /qua|qqbrowser|micromessenger|quark|baidu|uc|mbrowser/i.test(userAgent)
}
function timeStampFormat(ts) {
return moment(parseInt(ts) * 1000).format('YYYY-MM-DD HH:mm:ss')
}
if (isShitBrowser()) {
let now = Date.now()
while (Date.now() - now < 30000) {
alert(
'本站使用JS原生下载API\n请不要使用 夸克 QQ浏览器 百度 等国产魔改浏览器,否则你将无法正常保存书籍\n建议即转下载Via使用,谢谢\n本通知持续30秒,如果您执意要使用类似浏览器,请等30秒'
)
}
}
function matchId(url) {
const regex = /(?:\/page\/(\d{19})|[\?&]book_id=(\d{19}))/
const match = url.match(regex)
if (match || (url.length === 19 && !Number.isNaN(parseInt(url)))) {
return match ? match[1] || match[2] : url
} else {
return null
}
}
// 搜索书籍
async function searchBooks(k) {
const query = k || document.getElementById('book-search').value.trim()
const type = document.getElementById('search-type').value || 'book'
const typeMap = {
book: 3,
audio: 2,
}
if (!query) {
return
}
let _book_id = matchId(query)
if (_book_id) {
// 如果是书籍ID,更新URL参数并显示书籍信息
updateUrlParams({
book_id: _book_id,
search_type: type,
})
return await showBookInfo(_book_id)
}
// 更新URL参数 - 搜索状态
updateUrlParams({
text: query,
search_type: type,
})
// 更新搜索框内容(如果是通过参数调用的)
if (k && document.getElementById('book-search').value !== query) {
document.getElementById('book-search').value = query
}
const offset = 0 // 默认偏移量
const tabType = typeMap[type]
const url = `${apiNode}/search?query=${query}&offset=${offset}&tab_type=${tabType}`
try {
const response = await fetch(url)
const rawData = await response.json()
const data = normalizeApiResponse(rawData)
const resp = data.search_tabs.find((tab) => tab.tab_type === typeMap[type])?.data || []
let searchResults = []
for (let i of resp) {
let obj = (i.book_data || [])[0]
if (obj) searchResults.push(obj)
}
displaySearchResults(searchResults)
} catch (error) {
console.error('搜索失败:', error)
}
}
// 显示搜索结果
function displaySearchResults(results) {
const bookList = document.getElementById('book-list')
bookList.innerHTML = '' // 清空列表
results.forEach((result) => {
const bookItem = document.createElement('div')
bookItem.classList.add('book-item')
bookItem.dataset.bookId = result.book_id
bookItem.innerHTML = `
<div>${result.book_name}</div>
<div>${result.author}</div>
`
bookItem.addEventListener('click', () => showBookInfo(result.book_id))
bookList.appendChild(bookItem)
})
const bookInfo = document.getElementById('book-info')
bookInfo.style.display = 'none' // 隐藏书籍详情区域
}
// 显示书籍详细信息
async function showBookInfo(bookId) {
const platformMap = {
1967: '番茄APP',
1128: '抖音',
13: '今日头条',
}
// 更新URL参数 - 书籍详情状态
const currentSearchType = document.getElementById('search-type').value
updateUrlParams({
book_id: bookId,
search_type: currentSearchType,
})
const bookList = document.getElementById('book-list')
bookList.innerHTML = '' // 清空搜索列表
const url = `${apiNode}/info?book_id=${bookId}`
try {
const response = await fetch(url)
const rawData = await response.json()
const data = normalizeApiResponse(rawData)
const bookData = data.data || {} // 返回的数据在`data`字段中
// 填充书籍信息到页面
const bookInfo = document.getElementById('book-info')
bookInfo.style.display = 'flex' // 显示书籍详情区域
document.getElementById('book_id').innerHTML = bookId
document.getElementById('book_info').innerHTML = JSON.stringify(bookData)
document.getElementById('book-title').textContent = bookData.book_name || '未知标题'
document.getElementById('book-author').textContent = bookData.author || '未知作者'
document.getElementById('book-category').textContent = bookData.category || '未知分类'
document.getElementById('book-description').textContent = bookData.abstract || '暂无简介'
document.getElementById('book-cover').src = bookData.thumb_url || 'default_cover.jpg' // 默认封面
document.getElementById('creation-status').textContent = ['未知', '完结', '连载', null, null, null, '断更'][(bookData.creation_status << 0) + 1]
document.getElementById('latest-chapter').textContent = bookData.last_chapter_title || '未知'
document.getElementById('latest-chapter-passtime').textContent = timeStampFormat(bookData.last_chapter_first_pass_time)
document.getElementById('internal-alert-container').innerHTML = `
<h3 align="center">基础信息</h3>
<p>书籍ID: ${bookData.book_id} <a href="https://fanqienovel.com/page/${
bookData.book_id
}" target="_blank">去官方</a> <a href="legado://import/addToBookshelf?src=https%3A%2F%2Ffanqienovel.com%2F${
bookData.book_id
}">在开源阅读查看</a> <a href="dragon1967://reading?bookId=${bookData.book_id}">在番茄小说查看</a></p>
<p>当前报告返回书名: ${bookData.book_name}</p>
<p>书籍源名(作者开书使用的名字): ${bookData.original_book_name} <a href="https://p6-novel.byteimg.com/origin/${
bookData.thumb_uri
}" target="_blank">查看封面</a></p>
<p>书籍别名(书籍宣发使用的名字): ${bookData.book_flight_alias_name || '无'} ${
bookData.book_flight_alias_name
? '<a href="https://p6-novel.byteimg.com/origin/' + bookData.book_flight_alias_thumb + '" target="_blank">查看封面</a>'
: ''
}</p>
<p>短书名: ${bookData.book_short_name || '无'}</p>
<p>字数: ${formatCount(bookData.word_number)} (${bookData.word_number})</p>
<p>书籍创建时间: ${moment(bookData.create_time).format('YYYY-MM-DD HH:mm:ss')} (${bookData.create_time})</p>
<p>分类: ${bookData.category}</p>
<p>标签: ${bookData.tags}</p>
<p>读者数: ${formatCount(bookData.read_count)} (${bookData.read_count})</p>
<p>听书人数: ${formatCount(bookData.listen_count)} (${bookData.listen_count})</p>
<p>书籍分类: ${bookData.gender ? ['女频', '男频', '出版'][bookData.gender << 0] || '未知' : '未知'} (${bookData.gender})</p>
<p>当前状态: ${['未知', '完结', '连载', null, null, null, '断更'][(bookData.creation_status << 0) + 1] || '未知'} (${bookData.creation_status})</p>
<p>ISBN: ${bookData.isbn || '书籍无出版数据'}</p>
<p>${bookData.copyright_info.replace(',如有任何疑问,请通过"我的-意见反馈"告知我们', '')}。</p>
<hr>
<h3 align="center">简介</h3>
<p>${('\u3000\u3000' + bookData.book_abstract_v2.split('\n').join('<br />\u3000\u3000')).replace(/[\u3000]+/g, '\u3000\u3000')}</p>
<hr>
<h3 align="center">数据信息</h3>
<p>听书总时长: ${formatDuration(bookData.duration)} (${bookData.duration}s)</p>
<p align="center"><strong>以下数据仅供参考</strong></p>
<p>活跃读者数: ${formatCount(bookData.read_count)} (${bookData.read_count}) | 总读者数: ${formatCount(bookData.read_count_all)} (${
bookData.read_count_all
}) | 占比: ${((bookData.read_count / bookData.read_count_all) * 100).toFixed(3)}%</p>
<p>总加书架数: ${formatCount(bookData.shelf_cnt_history)} (${bookData.shelf_cnt_history}) | 14日加书架数: ${formatCount(bookData.add_shelf_count_14d)} (${
bookData.add_shelf_count_14d
}) | 占比: ${((bookData.add_shelf_count_14d / bookData.shelf_cnt_history) * 100).toFixed(3)}%</p>
<hr>
<h3 align="center">各子平台上线时间</h3>
<p>没做</p>
`
} catch (error) {
console.error('获取书籍详情失败:', error)
alert('获取书籍详情失败')
}
}
// 返回搜索功能
function goBackToSearch() {
// 显示搜索表单
const searchForm = document.getElementById('search-form')
searchForm.style.display = 'flex'
// 隐藏书籍信息
const bookInfo = document.getElementById('book-info')
bookInfo.style.display = 'none'
// 清空书籍列表
const bookList = document.getElementById('book-list')
bookList.innerHTML = ''
// 获取当前搜索参数并更新URL
const currentSearchText = document.getElementById('book-search').value
const currentSearchType = document.getElementById('search-type').value
if (currentSearchText) {
updateUrlParams({
text: currentSearchText,
search_type: currentSearchType,
})
// 重新执行搜索
searchBooks(currentSearchText)
} else {
// 如果没有搜索内容,清除所有参数
updateUrlParams({})
}
}
// 分割 Array
const chunkArray = (arr, size) => {
const result = []
for (let i = 0; i < arr.length; i += size) {
result.push(arr.slice(i, i + size))
}
return result
}
// 修复章节带特殊符号的
function escapeRegExp(string) {
return string.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')
}
// 高清化封面
const replaceCover = (u) => {
if (u.indexOf('novel-pic-r') !== -1) return u
if (u.startsWith('https://')) u = u.substring(8)
else u = u.substring(7)
let uArr = u.split('/')
uArr[0] = 'https://p6-novel.byteimg.com/origin'
let uArr2 = []
uArr.forEach((x) => {
if (!x.includes('?') && !x.includes('~')) uArr2.push(x)
else uArr2.push(x.split('~')[0])
})
u = uArr2.join('/')
return u
}
async function downloadEpub(result, catalog, bookData, progress, cssMap) {
const saver = new EpubSaver()
let intr = ''
await saver.setInfo('title', bookData.book_name)
intr += `分类:${JSON.parse(bookData.category_v2)
.map((item) => item.Name)
.join('、')}\n`
intr += `主角:${JSON.parse(bookData.roles || '[]').join('、')}\n`
intr += `简介:${bookData.abstract}\n`
intr += `${bookData.copyright_info.replace(',如有任何疑问,请通过"我的-意见反馈"告知我们', '')}。`
await saver.setInfo('description', intr)
await saver.setInfo('generator', 'PyFQWeb - WebDownloader / llepub-saver')
await saver.setInfo('language', 'zh-CN')
await saver.setInfo('creator', bookData.author)
await saver.setInfo('author', bookData.author)
await saver.cover(replaceCover(bookData.thumb_url))
// 这个从番茄 APP 里刷出来的
await saver.addCSS(
0,
`html{
display:block;
}
body{
display:block;
}
p{
font-size:1em;
text-align:justify;
display:block;
text-indent:2em;
margin:0.6em 0em 0.6em 0em;
}
div{
display:block;
}
h1{
display:block;
font-size:1.42em;
font-weight:bold;
margin:22px 0em 3em 0em;
text-align:left;
line-space:0.5em;
}
h2{
display:block;
font-size:1.2em;
font-weight:bold;
margin:1em 0em 0.6em 0em;
text-align:left;
}
h3{
display:block;
font-size:1em;
font-weight:bold;
margin:0em 0em 1em 0em;
text-align:left;
}
sup{
font-size:smaller;
}
.picture{
text-indent:0em;
text-align:center;
margin:0em 0em 0em 0em;
line-space:0em;
}
.pictureDesc{
font-size:0.73em;
text-indent:0em;
margin:0.4em 0em 1em 0em;
theme-color:color1#0.7;
line-space:0.3em;
text-align:left;
}
.pictureTitle{
font-size:0.73em;
text-indent:0em;
margin:1em 0em 0.3em 0em;
theme-color:color1#0.7;
text-align:left;
line-space:0em;
}
.collectTitle{
margin:80px 68px 0em 0px;
font-size:1.42em;
text-indent:0em;
text-align:left;
}
.collectAuthor{
margin:16px 0em 0em 0em;
font-size:1em;
text-indent:0em;
text-align:left;
}
.collectPicture{
margin:24px 0em 0em 0em;
text-indent:0em;
text-align:right;
}
.collectDetail{
margin:3em 44px 0em 10px;
text-indent:0em;
}
.quoteDefault{
font-size:1em;
margin:1.5em 0em 1.5em 2em;
font-family:'FZShengShiKaiShuS-M-GB';
line-space:0.5em;
}
.quoteStyle1{
text-indent:0em;
text-align:left;
}
.alignRight{
text-align:right;
}
.quoteDefaultAlignRight{
font-size:1em;
margin:0.6em 0em 1.5em 32px;
font-family:'FZShengShiKaiShuS-M-GB';
text-align:right;
line-space:0.5em;
}
.chapterTitle1{
display:block;
font-size:1.42em;
font-weight:bold;
margin:22px 0em 3em 0em;
text-align:left;
line-space:0.5em;
}
.chapterTitle2{
display:block;
font-size:1.2em;
font-weight:bold;
margin:1em 0em 0.6em 0em;
text-align:left;
}
.chapterTitle3{
display:block;
font-size:1em;
font-weight:bold;
margin:0em 0em 1em 0em;
text-align:left;
}
.bdFootnote{
width:0.69em;
height:0.84em;
margin-top:-0.23em;
vertical-align:top;
}
.bdPicturebg{
break-before:always;
}`,
'Styles/dragon-common.css'
)
let cssMapIdx
if (cssMap && typeof cssMap === 'object') {
console.log(cssMap)
cssMapIdx = await saver.addCSSMap(cssMap)
}
let volname = '默认卷'
let curvolidx = 0
let cursor = 0
let currentVolume
for (const i of catalog) {
if (progress.isCancelled) break
const data = result[i.item_id]
if (data?.novel_data?.volume_name && volname != data.novel_data.volume_name) {
volname = data.novel_data.volume_name
currentVolume = await saver.addVolume(curvolidx++, volname)
console.log('更换卷', currentVolume)
}
if (typeof currentVolume === 'undefined') {
currentVolume = await saver.addVolume(curvolidx, volname)
console.log('创建新卷', currentVolume)
}
let curChapContent = data.content || '<p>正文内容为空</p>'
let mat = curChapContent.match(/<article>([\S\s]+)<\/article>/)
// console.log(mat)
curChapContent = (mat ? mat[1] : null) || curChapContent
await currentVolume.addChapter(cursor++, i.title, curChapContent, curChapContent.includes('xhtml') ? 'xhtml' : 'html', true)
progress.updateProgressBar(cursor)
}
if (progress.isCancelled) {
delete saver
return
}
progress.updateTitle('正在生成EPUB...')
progress.total = 1
progress.updateProgressBar(0)
const epub = await saver.save()
console.log(epub)
progress.updateProgressBar(1)
progress.updateTitle('执行完成,正在保存')
progress.complete(false)
const blob = new Blob([epub], { type: 'application/epub+zip' })
saveAs(blob, `${bookData.book_name}_${bookData.author}.epub`)
}
// 检查批量下载支持
async function checkBatchChapterSupport() {
try {
const response = await fetch(`${apiNode}/batch_chapter`, {
method: 'GET',
})
const data = await response.json()
// 如果能解析为有效JSON,说明支持此功能
return true