forked from iChochy/NCE
-
Notifications
You must be signed in to change notification settings - Fork 81
Expand file tree
/
Copy pathindex.html
More file actions
997 lines (934 loc) · 34.1 KB
/
index.html
File metadata and controls
997 lines (934 loc) · 34.1 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
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="新概念英语免费在线点读平台,涵盖全部四册课文音频,支持逐句点读与A-B循环、听力播放、听写训练、播放历史和自定义课程管理,助力系统化英语学习。">
<meta name="keywords" content="新概念英语,在线点读,英语听力,英语学习,NCE">
<link rel="canonical" href="https://nce.hoothin.com/">
<meta property="og:locale" content="zh_CN">
<meta property="og:site_name" content="《新概念英语》在线点读">
<meta property="og:type" content="website">
<meta property="og:title" content="《新概念英语》在线点读">
<meta property="og:description" content="新概念英语免费在线点读平台,涵盖全部四册课文音频,支持逐句点读与A-B循环、听力播放、听写训练、播放历史和自定义课程管理,助力系统化英语学习。">
<meta property="og:url" content="https://nce.hoothin.com/">
<meta property="og:image" content="https://nce.hoothin.com/static/ogimage.jpg">
<meta property="og:image:type" content="image/jpeg">
<meta property="og:image:alt" content="新概念英语在线点读学习界面">
<meta name="twitter:card" content="summary_large_image">
<meta name="twitter:title" content="《新概念英语》在线点读">
<meta name="twitter:description" content="新概念英语免费在线点读平台,涵盖全部四册课文音频,支持逐句点读与A-B循环、听力播放、听写训练、播放历史和自定义课程管理,助力系统化英语学习。">
<meta name="twitter:image" content="https://nce.hoothin.com/static/ogimage.jpg">
<title>《新概念英语》在线点读</title>
<link rel="stylesheet" href="static/base.css">
<link rel="stylesheet" href="static/index.css">
<link rel="manifest" href="static/manifest.json">
<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-3321669220169470" crossorigin="anonymous"></script>
<script async src="https://www.googletagmanager.com/gtag/js?id=G-5282BCFM9W"></script>
<script>window.dataLayer=window.dataLayer||[];function gtag(){dataLayer.push(arguments)}gtag('js',new Date());gtag('config','G-5282BCFM9W');</script>
<script type="application/ld+json">
{"@context":"https://schema.org","@type":"WebApplication","name":"《新概念英语》在线点读","url":"https://nce.hoothin.com/","description":"新概念英语免费在线点读平台,涵盖全部四册课文音频,支持逐句点读与A-B循环、听力播放、听写训练、播放历史和自定义课程管理,助力系统化英语学习。","inLanguage":"zh-CN","applicationCategory":"EducationalApplication","operatingSystem":"Web","image":"https://nce.hoothin.com/static/ogimage.jpg","publisher":{"@type":"Person","name":"hoothin"}}
</script>
</head>
<body>
<canvas id="particle-canvas"></canvas>
<div class="container">
<div class="header index-header">
<div class="header-text">
<h1>新概念英语</h1>
<p>New Concept English</p>
</div>
<button type="button" id="custom-settings-btn" class="settings-btn">自定义设置</button>
</div>
</div>
<div class="book-container history-section" id="history-container" style="display: none;">
<div class="history-header">
<div class="history-title-group">
<span class="history-icon">
<span></span>
<span></span>
<span></span>
</span>
<div>
<h3>最近播放</h3>
<p class="history-subtitle">继续上次停留的课程</p>
</div>
</div>
<button id="expand-history-btn" class="history-toggle-btn">展开</button>
</div>
<hr class="history-divider">
<a id="history-preview" class="history-preview" href="#"></a>
<div id="history-list"></div>
</div>
<style>
#particle-canvas {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
z-index: -1;
opacity: 0.5;
background-color: var(--bg-color);
}
/* 半透明容器和卡片 */
.book-container {
background-color: rgba(24, 24, 24, 0.75) !important;
backdrop-filter: blur(10px);
-webkit-backdrop-filter: blur(10px);
}
.book-card {
background-color: rgba(40, 40, 40, 0.6) !important;
backdrop-filter: blur(8px);
-webkit-backdrop-filter: blur(8px);
}
.book-card:hover {
background-color: rgba(51, 51, 51, 0.8) !important;
}
.book-card::before {
content: '';
position: absolute;
top: 0;
left: -100%;
z-index: 1;
width: 100%;
height: 100%;
background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.4), transparent);
}
.book-card:hover::before {
left: 100%;
transition: left 0.5s;
}
.history-section {
background-color: rgba(24, 24, 24, 0.75) !important;
backdrop-filter: blur(10px);
-webkit-backdrop-filter: blur(10px);
}
.history-card {
background: rgba(33, 33, 33, 0.7) !important;
backdrop-filter: blur(8px);
-webkit-backdrop-filter: blur(8px);
}
.settings-modal {
backdrop-filter: blur(5px);
-webkit-backdrop-filter: blur(5px);
}
.settings-modal__content {
background: rgba(24, 24, 24, 0.85) !important;
backdrop-filter: blur(15px);
-webkit-backdrop-filter: blur(15px);
}
/* 低性能模式:禁用backdrop-filter */
body.low-performance .book-container,
body.low-performance .book-card,
body.low-performance .history-section,
body.low-performance .history-card,
body.low-performance .settings-modal,
body.low-performance .settings-modal__content,
body.low-performance .index-header .settings-btn,
body.low-performance .history-preview,
body.low-performance .history-toggle-btn,
body.low-performance .settings-actions button,
body.low-performance #custom-data-input {
backdrop-filter: none !important;
-webkit-backdrop-filter: none !important;
}
/* 低性能模式下使用更深的背景色补偿 */
body.low-performance .book-container,
body.low-performance .history-section {
background-color: rgba(24, 24, 24, 0.92) !important;
}
body.low-performance .book-card,
body.low-performance .history-card {
background-color: rgba(40, 40, 40, 0.85) !important;
}
body.low-performance .settings-modal__content {
background: rgba(24, 24, 24, 0.95) !important;
}
.index-header {
position: relative;
}
.index-header .settings-btn {
position: absolute;
top: 20px;
right: 20px;
border-radius: 999px;
border: 1px solid rgba(29, 185, 84, 0.55);
background: rgba(29, 185, 84, 0.15);
backdrop-filter: blur(8px);
-webkit-backdrop-filter: blur(8px);
color: var(--text-color);
padding: 8px 18px;
font-size: 0.92em;
font-weight: 600;
cursor: pointer;
transition: all 0.2s ease;
opacity: 0.3;
}
.index-header .settings-btn:hover {
background: rgba(29, 185, 84, 0.35);
backdrop-filter: blur(10px);
-webkit-backdrop-filter: blur(10px);
transform: translateY(-2px);
box-shadow: 0 10px 24px rgba(29, 185, 84, 0.25);
opacity: 1;
}
.index-header .settings-btn:focus {
outline: 2px solid rgba(29, 185, 84, 0.6);
outline-offset: 2px;
}
@media (max-width: 600px) {
.index-header .settings-btn {
top: 16px;
right: 16px;
padding: 6px 14px;
}
}
.history-section {
position: relative;
overflow: hidden;
flex: 0 0 auto;
margin-bottom: 20px;
}
.book-container.history-section.collapsed {
padding: 10px 16px 14px;
}
.history-section::before {
content: "";
position: absolute;
top: -45%;
right: -25%;
width: 70%;
height: 170%;
background: radial-gradient(circle at top right, rgba(29, 185, 84, 0.2), transparent 65%);
pointer-events: none;
}
.history-section > * {
position: relative;
}
.history-header {
display: flex;
justify-content: space-between;
align-items: center;
gap: 20px;
flex-wrap: wrap;
}
.history-section.collapsed .history-header {
gap: 14px;
}
.history-title-group {
display: flex;
align-items: center;
gap: 18px;
flex: 1;
min-width: 240px;
}
.history-section.collapsed .history-title-group {
gap: 12px;
min-width: 200px;
}
.history-title-group h3 {
font-size: 1.25em;
font-weight: 600;
margin: 0;
}
.history-section.collapsed .history-title-group h3 {
font-size: 1.05em;
}
.history-subtitle {
margin-top: 4px;
font-size: 0.85em;
color: var(--text-color-dark);
letter-spacing: 0.3px;
}
.history-section.collapsed .history-subtitle { display: none; }
.history-icon {
display: inline-flex;
align-items: flex-end;
justify-content: center;
gap: 4px;
width: 46px;
height: 46px;
border-radius: 14px;
padding: 8px;
background: linear-gradient(135deg, rgba(29, 185, 84, 0.35), rgba(29, 185, 84, 0.12));
box-shadow: 0 10px 24px rgba(29, 185, 84, 0.2);
}
.history-section.collapsed .history-icon {
width: 34px;
height: 34px;
border-radius: 10px;
padding: 5px;
}
.history-icon span {
width: 5px;
border-radius: 3px;
background: var(--primary-color);
opacity: 0.75;
}
.history-icon span:nth-child(1) { height: 16px; }
.history-icon span:nth-child(2) { height: 26px; }
.history-icon span:nth-child(3) { height: 20px; }
.history-toggle-btn {
display: none;
border-radius: 999px;
padding: 7px 18px;
border: 1px solid rgba(29, 185, 84, 0.45);
background: rgba(29, 185, 84, 0.12);
backdrop-filter: blur(8px);
-webkit-backdrop-filter: blur(8px);
color: var(--text-color);
font-size: 0.85em;
font-weight: 500;
cursor: pointer;
transition: all 0.2s ease;
}
.history-section.collapsed .history-toggle-btn {
padding: 4px 12px;
font-size: 0.75em;
}
.history-toggle-btn:hover {
background: rgba(29, 185, 84, 0.22);
backdrop-filter: blur(10px);
-webkit-backdrop-filter: blur(10px);
border-color: var(--primary-color);
color: var(--primary-color);
}
.history-divider {
border-top-color: rgba(255, 255, 255, 0.08);
margin: 14px 0 20px;
}
.history-section.collapsed .history-divider { display: none; }
#history-list {
display: flex;
gap: 18px;
overflow-x: auto;
padding: 4px 4px 12px;
scroll-snap-type: x mandatory;
}
.history-section.collapsed #history-list { display: none; }
#history-list::-webkit-scrollbar {
height: 6px;
}
#history-list::-webkit-scrollbar-thumb {
background: rgba(255, 255, 255, 0.18);
border-radius: 999px;
}
.history-card {
background: rgba(33, 33, 33, 0.95);
border-radius: 14px;
border: 1px solid rgba(255, 255, 255, 0.05);
box-shadow: 0 14px 34px rgba(0, 0, 0, 0.4);
overflow: hidden;
text-decoration: none;
color: inherit;
transition: transform 0.25s ease, box-shadow 0.25s ease, border-color 0.25s ease;
display: flex;
flex-direction: column;
min-width: 180px;
width: 180px;
scroll-snap-align: start;
}
.history-card:hover {
transform: translateY(-6px) scale(1.015);
box-shadow: 0 20px 40px rgba(0, 0, 0, 0.45);
border-color: rgba(29, 185, 84, 0.5);
}
.history-card img {
width: 100%;
height: 110px;
object-fit: cover;
}
.history-preview {
display: none;
align-items: center;
gap: 14px;
padding: 8px 12px;
border-radius: 12px;
background: rgba(255, 255, 255, 0.06);
backdrop-filter: blur(8px);
-webkit-backdrop-filter: blur(8px);
border: 1px solid rgba(255, 255, 255, 0.08);
transition: border-color 0.2s ease, background 0.2s ease;
text-decoration: none;
color: inherit;
min-height: 48px;
margin-top: 6px;
}
.history-preview:hover {
border-color: rgba(29, 185, 84, 0.45);
background: rgba(29, 185, 84, 0.12);
backdrop-filter: blur(10px);
-webkit-backdrop-filter: blur(10px);
}
.history-preview img {
width: 44px;
height: 44px;
border-radius: 10px;
object-fit: cover;
}
.history-preview-info {
display: flex;
flex-direction: column;
gap: 2px;
}
.history-preview-label {
font-size: 0.75em;
color: var(--text-color-dark);
letter-spacing: 0.4px;
text-transform: uppercase;
}
.history-preview-title {
font-size: 0.9em;
font-weight: 600;
color: var(--text-color);
line-height: 1.3;
}
.history-section.collapsed .history-preview { display: flex; }
.history-card-info {
padding: 12px 14px 16px;
flex-grow: 1;
display: flex;
flex-direction: column;
gap: 6px;
}
.history-card-title {
font-weight: 600;
font-size: 0.95em;
margin: 0;
color: var(--text-color);
line-height: 1.4;
}
.history-card-book {
font-size: 0.75em;
color: var(--text-color-dark);
margin: 0;
letter-spacing: 0.4px;
}
.history-list-grid {
display: grid !important;
grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
gap: 20px;
overflow: visible;
padding-bottom: 0;
scroll-snap-type: none;
}
.history-list-grid .history-card {
min-width: 0;
width: 100%;
}
@media (max-width: 768px) {
.history-title-group {
gap: 14px;
}
.history-icon {
width: 40px;
height: 40px;
border-radius: 12px;
padding: 6px;
}
.history-card {
min-width: 160px;
width: 160px;
}
.history-card img {
height: 100px;
}
}
.settings-modal {
position: fixed;
inset: 0;
background: rgba(0, 0, 0, 0.65);
display: none;
align-items: center;
justify-content: center;
padding: 20px;
z-index: 1000;
}
.settings-modal.open {
display: flex;
}
.settings-modal__content {
position: relative;
width: min(680px, 100%);
background: var(--container-bg);
border-radius: 16px;
border: 1px solid var(--container-highlight);
padding: 24px;
box-shadow: 0 20px 40px rgba(0, 0, 0, 0.55);
display: flex;
flex-direction: column;
gap: 16px;
}
.settings-modal__content::after {
content: "\0040\0068\006F\006F\0074\0068\0069\006E";
display: block;
position: absolute;
bottom: 0;
right: 0;
text-align: right;
font-size: 0.8em;
color: rgba(255, 255, 255, 0.02);
letter-spacing: 0.5px;
}
.settings-modal__content h2 {
font-size: 1.3em;
margin-bottom: 2px;
}
.settings-modal__content > a {
position: absolute; bottom: 20px; color: tomato;
}
.settings-description {
font-size: 0.9em;
color: var(--text-color-dark);
line-height: 1.5;
}
#custom-data-input {
width: 100%;
min-height: 220px;
border-radius: 12px;
border: 1px solid var(--container-highlight);
background: rgba(24, 24, 24, 0.9);
backdrop-filter: blur(10px);
-webkit-backdrop-filter: blur(10px);
color: var(--text-color);
padding: 12px;
resize: vertical;
font-family: "Fira Code", "Consolas", "Courier New", monospace;
font-size: 0.95em;
}
.settings-actions {
display: flex;
flex-wrap: wrap;
gap: 12px;
justify-content: flex-end;
margin-top: 10px;
}
.settings-actions button {
border-radius: 999px;
border: 1px solid rgba(29, 185, 84, 0.45);
background: rgba(29, 185, 84, 0.12);
backdrop-filter: blur(8px);
-webkit-backdrop-filter: blur(8px);
color: var(--text-color);
padding: 8px 20px;
font-size: 0.9em;
font-weight: 500;
cursor: pointer;
transition: all 0.2s ease;
}
.settings-actions button.primary {
background: var(--primary-color);
color: #0f0f0f;
border-color: var(--primary-color);
backdrop-filter: none;
}
.settings-actions button:hover {
transform: translateY(-1px);
box-shadow: 0 10px 24px rgba(0, 0, 0, 0.35);
backdrop-filter: blur(10px);
-webkit-backdrop-filter: blur(10px);
}
.settings-actions button.primary:hover {
backdrop-filter: none;
}
.settings-feedback {
min-height: 20px;
font-size: 0.85em;
color: var(--text-color-dark);
margin-top: 6px;
}
.settings-feedback.success {
color: #55d86c;
}
.settings-feedback.error {
color: #ff6b6b;
}
.settings-modal__close {
position: absolute;
top: 12px;
right: 14px;
background: transparent;
border: none;
color: var(--text-color-dark);
font-size: 1.3em;
cursor: pointer;
}
.settings-modal__close:hover {
color: var(--text-color);
}
</style>
<div class="book-container">
<div class="book-header">
<h3>全四册课文导航</h3>
</div>
<hr>
<div class="books-nav">
<a href="book.html#NCE1">
<div class="book-card" data-book="1">
<img src="images/NCE1.jpg" alt="First Things First">
<div class="book-info">
<div class="book-number">第一册</div>
<div class="book-title">First Things First</div>
<div class="book-subtitle">英语初阶</div>
<div class="lesson-count">144课</div>
</div>
</div>
</a>
<a href="book.html#NCE2">
<div class="book-card" data-book="2">
<img src="images/NCE2.jpg" alt="Practice and Progress">
<div class="book-info">
<div class="book-number">第二册</div>
<div class="book-title">Practice and Progress</div>
<div class="book-subtitle">实践与进步</div>
<div class="lesson-count">96课</div>
</div>
</div>
</a>
<a href="book.html#NCE3">
<div class="book-card" data-book="3">
<img src="images/NCE3.jpg" alt="Developing Skills">
<div class="book-info">
<div class="book-number">第三册</div>
<div class="book-title">Developing Skills</div>
<div class="book-subtitle">培养技能</div>
<div class="lesson-count">60课</div>
</div>
</div>
</a>
<a href="book.html#NCE4">
<div class="book-card" data-book="4">
<img src="images/NCE4.jpg" alt="Fluency in English">
<div class="book-info">
<div class="book-number">第四册</div>
<div class="book-title">Fluency in English</div>
<div class="book-subtitle">流利英语</div>
<div class="lesson-count">48课</div>
</div>
</div>
</a>
</div>
</div>
<div id="custom-settings-modal" class="settings-modal" aria-hidden="true">
<div class="settings-modal__content" role="dialog" aria-modal="true" aria-labelledby="custom-settings-title">
<button type="button" id="custom-data-close" class="settings-modal__close" aria-label="关闭">×</button>
<h2 id="custom-settings-title">自定义数据</h2>
<p class="settings-description">请输入 JSON 对象,形如 { "书名": [{ "title": "课名", "filename": "https://.../音频.mp3", "lrc": "https://.../歌词.lrc" }] }。</p>
<form id="custom-data-form">
<textarea id="custom-data-input" name="customData" placeholder='{"我的收藏": [{"title": "自定义课文", "filename": "https://example.com/audio.mp3"}]}'></textarea>
<div class="settings-actions">
<button type="submit" class="primary">保存</button>
<button type="button" id="custom-data-clear">清空</button>
<button type="button" id="custom-data-cancel">取消</button>
</div>
<div id="custom-data-feedback" class="settings-feedback" role="status" aria-live="polite"></div>
</form>
<a href="https://github.com/hoothin/NCE/discussions/categories/%E8%87%AA%E5%AE%9A%E4%B9%89%E8%8B%B1%E8%AF%AD%E8%AF%BE%E6%9C%AC%E5%88%86%E4%BA%AB">自定义课本分享</a>
</div>
</div>
<footer>
<hr>
<p>© 2025 <a target="_blank" href="https://www.hoothin.com">hoothin</a>.</p>
</footer>
<script src="static/particle-bg.js"></script>
<script src="static/utils.js"></script>
<script>
document.addEventListener('DOMContentLoaded', () => {
const historyContainer = document.getElementById('history-container');
const historyList = document.getElementById('history-list');
const expandBtn = document.getElementById('expand-history-btn');
const historyPreview = document.getElementById('history-preview');
const booksNav = document.querySelector('.books-nav');
const settingsBtn = document.getElementById('custom-settings-btn');
const settingsModal = document.getElementById('custom-settings-modal');
const customDataForm = document.getElementById('custom-data-form');
const customDataInput = document.getElementById('custom-data-input');
const customDataFeedback = document.getElementById('custom-data-feedback');
const customDataCancel = document.getElementById('custom-data-cancel');
const customDataClear = document.getElementById('custom-data-clear');
const customDataClose = document.getElementById('custom-data-close');
const bookNumToChinese = { '1': '一', '2': '二', '3': '三', '4': '四' };
const defaultBookImages = {
'1': 'images/NCE1.jpg',
'2': 'images/NCE2.jpg',
'3': 'images/NCE3.jpg',
'4': 'images/NCE4.jpg'
};
const utils = window.NCEUtils;
if (!utils) {
console.error('NCEUtils is not available.');
return;
}
const {
createPlaceholderCover,
parseCustomBookKey,
loadStoredCustomData,
formatCustomData,
sanitizeCustomDataInput,
prepareCustomLessons
} = utils;
const PLACEHOLDER_CARD_OPTIONS = { width: 200, height: 200 };
function getRuntimeCustomData() {
const raw = loadStoredCustomData();
if (!raw) {
return null;
}
const prepared = prepareCustomLessons(raw, { deriveLrc: true });
return Object.keys(prepared).length ? prepared : null;
}
function showFeedback(message, type) {
if (!customDataFeedback) {
return;
}
customDataFeedback.textContent = message;
customDataFeedback.className = type ? `settings-feedback ${type}` : 'settings-feedback';
}
function buildHistoryMeta(item) {
const isCustom = item && (item.bookType === 'custom' || item.book === 'CUSTOM' || item.customBookName);
if (isCustom) {
const rawKey = item.customBookName || '';
const { name: bookName, cover } = parseCustomBookKey(rawKey);
const lessonIndex = typeof item.customLessonIndex === 'number'
? item.customLessonIndex
: parseInt(item.lesson, 10) || 0;
return {
href: rawKey ? `lesson.html#CUSTOM/${encodeURIComponent(rawKey)}/${lessonIndex}` : '#',
cover: cover || createPlaceholderCover(bookName, PLACEHOLDER_CARD_OPTIONS),
label: bookName,
title: item.title || '未命名课程'
};
}
const book = String(item && item.book ? item.book : '');
const bookLabel = bookNumToChinese[book] ? `第 ${bookNumToChinese[book]} 册` : '新概念英语';
const cover = defaultBookImages[book] || defaultBookImages['1'];
const lesson = encodeURIComponent(item && item.lesson ? item.lesson : '');
return {
href: `lesson.html#NCE${book}/${lesson}`,
cover,
label: bookLabel,
title: item && item.title ? item.title : '未命名课程'
};
}
function createHistoryCard(meta) {
const card = document.createElement('a');
card.className = 'history-card';
card.href = meta.href;
const img = document.createElement('img');
img.src = meta.cover;
img.alt = meta.label;
const info = document.createElement('div');
info.className = 'history-card-info';
const titleEl = document.createElement('p');
titleEl.className = 'history-card-title';
titleEl.textContent = meta.title;
const labelEl = document.createElement('p');
labelEl.className = 'history-card-book';
labelEl.textContent = meta.label;
info.append(titleEl, labelEl);
card.append(img, info);
return card;
}
function updateHistoryPreview(meta) {
if (!historyPreview) {
return;
}
historyPreview.style.display = '';
historyPreview.href = meta.href;
historyPreview.innerHTML = '';
const img = document.createElement('img');
img.src = meta.cover;
img.alt = meta.label;
const info = document.createElement('div');
info.className = 'history-preview-info';
const label = document.createElement('span');
label.className = 'history-preview-label';
label.textContent = '继续播放';
const title = document.createElement('span');
title.className = 'history-preview-title';
title.textContent = meta.title;
info.append(label, title);
historyPreview.append(img, info);
}
function renderHistory() {
if (!historyContainer || !historyList || !historyPreview) {
return;
}
const history = JSON.parse(localStorage.getItem('ncePlaybackHistory') || '[]');
if (!history.length) {
historyContainer.style.display = 'none';
historyPreview.style.display = 'none';
historyPreview.href = '#';
if (expandBtn) {
expandBtn.style.display = 'none';
}
historyList.innerHTML = '';
return;
}
historyContainer.style.display = 'block';
historyContainer.classList.add('collapsed');
historyList.classList.remove('history-list-grid');
historyList.innerHTML = '';
const firstMeta = buildHistoryMeta(history[0]);
historyList.appendChild(createHistoryCard(firstMeta));
updateHistoryPreview(firstMeta);
if (expandBtn) {
expandBtn.style.display = history.length > 1 ? 'inline-block' : 'none';
expandBtn.textContent = '展开';
expandBtn.onclick = null;
if (history.length > 1) {
let isExpanded = false;
expandBtn.onclick = () => {
isExpanded = !isExpanded;
expandBtn.textContent = isExpanded ? '收起' : '展开';
historyContainer.classList.toggle('collapsed', !isExpanded);
if (isExpanded) {
historyList.classList.add('history-list-grid');
historyList.innerHTML = '';
history.forEach((item) => {
historyList.appendChild(createHistoryCard(buildHistoryMeta(item)));
});
} else {
historyList.classList.remove('history-list-grid');
historyList.innerHTML = '';
historyList.appendChild(createHistoryCard(firstMeta));
historyList.scrollLeft = 0;
}
};
}
}
}
function clearCustomCards() {
if (!booksNav) {
return;
}
booksNav.querySelectorAll('a[data-custom-book-anchor]').forEach((anchor) => anchor.remove());
}
function renderCustomBooks() {
if (!booksNav) {
return;
}
clearCustomCards();
const customData = getRuntimeCustomData();
const entries = customData ? Object.entries(customData) : [];
if (!entries.length) {
return;
}
entries.forEach(([bookKey, lessons]) => {
const count = Array.isArray(lessons) ? lessons.length : 0;
if (!count) {
return;
}
const { name: displayName, cover } = parseCustomBookKey(bookKey);
const anchor = document.createElement('a');
anchor.dataset.customBookAnchor = 'true';
anchor.href = `book.html#CUSTOM/${encodeURIComponent(bookKey)}`;
const card = document.createElement('div');
card.className = 'book-card';
card.dataset.customBook = displayName;
const img = document.createElement('img');
img.src = cover || createPlaceholderCover(displayName, PLACEHOLDER_CARD_OPTIONS);
img.alt = displayName;
const info = document.createElement('div');
info.className = 'book-info';
const number = document.createElement('div');
number.className = 'book-number';
number.textContent = '自定义';
const title = document.createElement('div');
title.className = 'book-title';
title.textContent = displayName;
const subtitle = document.createElement('div');
subtitle.className = 'book-subtitle';
subtitle.textContent = '自定义课程';
const lessonCount = document.createElement('div');
lessonCount.className = 'lesson-count';
lessonCount.textContent = `${count}课`;
info.append(number, title, subtitle, lessonCount);
card.append(img, info);
anchor.append(card);
booksNav.append(anchor);
});
}
function openSettingsModal() {
if (!settingsModal || !customDataInput) {
return;
}
const data = loadStoredCustomData();
customDataInput.value = data ? formatCustomData(data) : '';
showFeedback('', '');
settingsModal.classList.add('open');
settingsModal.setAttribute('aria-hidden', 'false');
customDataInput.focus();
}
function closeSettingsModal() {
if (!settingsModal) {
return;
}
settingsModal.classList.remove('open');
settingsModal.setAttribute('aria-hidden', 'true');
}
if (settingsBtn && settingsModal && customDataForm && customDataInput) {
settingsBtn.addEventListener('click', openSettingsModal);
customDataForm.addEventListener('submit', (event) => {
event.preventDefault();
const rawValue = customDataInput.value.trim();
if (!rawValue) {
localStorage.removeItem('nceCustomData');
customDataInput.value = '';
showFeedback('已清空自定义数据。', 'success');
renderCustomBooks();
renderHistory();
return;
}
try {
const parsed = JSON.parse(rawValue);
const sanitized = sanitizeCustomDataInput(parsed);
localStorage.setItem('nceCustomData', JSON.stringify(sanitized));
customDataInput.value = formatCustomData(sanitized);
showFeedback('已保存自定义数据。', 'success');
renderCustomBooks();
renderHistory();
setTimeout(() => {
closeSettingsModal();
}, 300);
} catch (error) {
const message = error && error.message ? error.message : '请检查输入格式。';
showFeedback(`保存失败:${message}`, 'error');
}
});
if (customDataCancel) {
customDataCancel.addEventListener('click', () => {
closeSettingsModal();
});
}
if (customDataClear) {
customDataClear.addEventListener('click', () => {
localStorage.removeItem('nceCustomData');
customDataInput.value = '';
showFeedback('已清空自定义数据。', 'success');
renderCustomBooks();
renderHistory();
});
}
if (customDataClose) {
customDataClose.addEventListener('click', () => {
closeSettingsModal();
});
}
settingsModal.addEventListener('click', (event) => {
if (event.target === settingsModal) {
closeSettingsModal();
}
});
document.addEventListener('keydown', (event) => {
if (event.key === 'Escape' && settingsModal.classList.contains('open')) {
closeSettingsModal();
}
});
}
renderHistory();
renderCustomBooks();
});
</script>
</body>
</html>