forked from luzhenhua/NCE-Flow
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
executable file
·674 lines (618 loc) · 28 KB
/
index.html
File metadata and controls
executable file
·674 lines (618 loc) · 28 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
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
<meta name="theme-color" content="#6366f1">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="default">
<meta name="apple-mobile-web-app-title" content="NCE Flow">
<link rel="icon" href="favicon.ico">
<link rel="apple-touch-icon" href="icons/apple-touch-icon.png">
<link rel="manifest" href="manifest.json">
<title>NCE Flow</title>
<link rel="stylesheet" href="assets/styles.css">
<!-- Microsoft Clarity 统计代码 -->
<script type="text/javascript">
(function (c, l, a, r, i, t, y) {
c[a] = c[a] || function () { (c[a].q = c[a].q || []).push(arguments) };
t = l.createElement(r); t.async = 1; t.src = "https://www.clarity.ms/tag/" + i;
y = l.getElementsByTagName(r)[0]; y.parentNode.insertBefore(t, y);
})(window, document, "clarity", "script", "tvjv632zgs");
</script>
<!-- Microsoft Clarity 代码结束 -->
<script src="assets/app.js" defer></script>
<script src="assets/search.js" defer></script>
<!-- 主题切换逻辑 -->
<script>
(function () {
const THEME_KEY = 'nce_theme';
// Icons
const SUN_ICON = '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="5"></circle><line x1="12" y1="1" x2="12" y2="3"></line><line x1="12" y1="21" x2="12" y2="23"></line><line x1="4.22" y1="4.22" x2="5.64" y2="5.64"></line><line x1="18.36" y1="18.36" x2="19.78" y2="19.78"></line><line x1="1" y1="12" x2="3" y2="12"></line><line x1="21" y1="12" x2="23" y2="12"></line><line x1="4.22" y1="19.78" x2="5.64" y2="18.36"></line><line x1="18.36" y1="5.64" x2="19.78" y2="4.22"></line></svg>';
const MOON_ICON = '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M21 12.79A9 9 0 1 1 11.21 3 7 7 0 0 0 21 12.79z"></path></svg>';
function getPreferredTheme() {
const saved = localStorage.getItem(THEME_KEY);
if (saved) return saved;
return window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light';
}
function applyTheme(theme) {
const root = document.documentElement;
const scrollX = window.scrollX || 0;
const scrollY = window.scrollY || 0;
root.classList.remove('dark-theme', 'light-theme');
root.classList.add(theme + '-theme');
if (document.body) {
document.body.classList.remove('dark-theme', 'light-theme');
document.body.classList.add(theme + '-theme');
}
try { root.style.colorScheme = theme; } catch (_) { }
const computedBg = (() => {
try {
const base = document.body ? getComputedStyle(document.body) : getComputedStyle(root);
return base.getPropertyValue('--bg').trim();
} catch (_) {
return '';
}
})();
const bg = computedBg || (theme === 'dark' ? '#09090b' : '#ffffff');
root.style.backgroundColor = bg;
if (document.body) document.body.style.backgroundColor = bg;
void root.offsetHeight;
const btn = document.getElementById('themeToggleBtn');
if (btn) {
// If current is dark, show SUN to switch to light. If light, show MOON.
btn.innerHTML = theme === 'dark' ? SUN_ICON : MOON_ICON;
btn.setAttribute('aria-label', theme === 'dark' ? '切换到浅色模式' : '切换到深色模式');
}
if (document.body) {
requestAnimationFrame(() => {
// iOS/WKWebView: sometimes tiles don't repaint until a scroll happens.
const body = document.body;
const prevOpacity = body.style.opacity;
body.style.opacity = '0.99999';
const doc = document.documentElement;
const maxY = Math.max(0, doc.scrollHeight - window.innerHeight);
const y0 = Math.max(0, Math.min(scrollY, maxY));
const y1 = maxY ? (y0 < maxY ? y0 + 1 : Math.max(0, y0 - 1)) : y0;
window.scrollTo(scrollX, y1);
requestAnimationFrame(() => {
body.style.opacity = prevOpacity;
window.scrollTo(scrollX, y0);
});
});
}
}
function toggleTheme() {
const isDark = document.documentElement.classList.contains('dark-theme') ||
(document.body && document.body.classList.contains('dark-theme'));
const next = isDark ? 'light' : 'dark';
localStorage.setItem(THEME_KEY, next);
applyTheme(next);
}
function init() {
const theme = getPreferredTheme();
applyTheme(theme);
const btn = document.getElementById('themeToggleBtn');
if (btn) btn.addEventListener('click', toggleTheme);
}
if (window.matchMedia) {
const colorSchemeQuery = window.matchMedia('(prefers-color-scheme: dark)');
const handleSystemChange = (e) => {
if (!localStorage.getItem(THEME_KEY)) {
applyTheme(e.matches ? 'dark' : 'light');
}
};
if (colorSchemeQuery.addEventListener) colorSchemeQuery.addEventListener('change', handleSystemChange);
else if (colorSchemeQuery.addListener) colorSchemeQuery.addListener(handleSystemChange);
}
if (document.readyState === 'loading') {
document.addEventListener('DOMContentLoaded', init);
} else {
init();
}
})();
</script>
<script defer>
document.addEventListener('DOMContentLoaded', () => {
const container = document.getElementById('lessons');
const lastWrap = document.getElementById('lastSeenWrap');
const lastBox = document.getElementById('lastSeen');
const header = document.getElementById('bookTitle');
const segBooks = document.querySelectorAll('[data-book]');
const FAV_KEY = 'nce_favs';
const RECENT_KEY = 'nce_recents';
const getBook = () => (location.hash.slice(1) || 'NCE1').replace(/[^\w\d]/g, '');
function activeTab(book) { segBooks.forEach(b => b.classList.toggle('active', b.dataset.book === book)); }
async function load() {
try {
const res = await fetch('static/data.json');
if (!res.ok) {
console.error('Failed to fetch data.json:', res.status, res.statusText);
document.getElementById('lessons').innerHTML = '<div style="color: red; padding: 20px;">加载课程数据失败,请检查 static/data.json 文件</div>';
return;
}
const data = await res.json();
render(data);
} catch (error) {
console.error('Error loading data:', error);
document.getElementById('lessons').innerHTML = '<div style="color: red; padding: 20px;">网络错误或数据格式问题</div>';
}
}
function getFavs() { try { return new Set(JSON.parse(localStorage.getItem(FAV_KEY) || '[]')); } catch (_) { return new Set(); } }
function saveFavs(set) { try { localStorage.setItem(FAV_KEY, JSON.stringify(Array.from(set))); } catch (_) { } }
function lessonId(book, lesson) { return `${book}/${lesson.filename}`; }
function toLessonHref(book, lesson) { return `lesson.html#${book}/${lesson.filename}`; }
function fmtTime(t) { t = Math.max(0, Math.floor(t || 0)); const m = Math.floor(t / 60); const s = t % 60; return `${m}:${String(s).padStart(2, '0')}`; }
function itemHTML(book, lesson, idx, favs) {
const id = lessonId(book, lesson);
const isFav = favs.has(id);
const num = parseInt(book.replace('NCE', '')) || 1;
let lessonNumber = num === 1 ? `${idx * 2 + 1}&${idx * 2 + 2}` : String(idx + 1);
return `
<a class="lesson-item" href="${toLessonHref(book, lesson)}" data-id="${id}">
<div class="lesson-content">
<div class="lesson-num">第${lessonNumber}课</div>
<div class="lesson-title">${lesson.title}</div>
</div>
<button class="fav-btn ${isFav ? 'active' : ''}" role="button" aria-label="收藏" aria-pressed="${isFav}" data-id="${id}" onclick="event.preventDefault(); event.stopPropagation(); toggleFav('${id}')">
<svg viewBox="0 0 16 16" aria-hidden="true">
<path d="M8 12.027 3.297 14.5l.9-5.243L.1 5.997l5.258-.764L8 0l2.642 5.233 5.258.764-4.097 3.26.9 5.243L8 12.027Z"></path>
</svg>
</button>
</a>`;
}
function render(data) {
const book = getBook();
const num = parseInt(book.replace('NCE', '')) || 1;
// header.textContent = `新概念英语第${['一','二','三','四'][num-1]}册`;
activeTab(book);
const lessons = data[num] || [];
const favs = getFavs();
try {
const recRaw = JSON.parse(localStorage.getItem(RECENT_KEY) || '[]');
const rec = recRaw.filter(x => typeof x?.id === 'string' && x.id.startsWith(book + '/'))
.sort((a, b) => (b.ts || 0) - (a.ts || 0))[0];
if (rec) {
const i = lessons.findIndex(l => `${book}/${l.filename}` === rec.id);
if (i >= 0) {
const lesson = lessons[i];
let posTxt = '';
try {
const map = JSON.parse(localStorage.getItem('nce_lastpos') || '{}');
const lp = map[rec.id];
if (lp && (lp.idx >= 0 || lp.t >= 0)) {
const num = parseInt(book.replace('NCE', '')) || 1;
const lessonNumber = num === 1 ? `${i * 2 + 1}&${i * 2 + 2}` : String(i + 1);
const tt = (lp.t >= 0) ? fmtTime(lp.t) : '';
posTxt = [`第${lessonNumber}课`, tt].filter(Boolean).join(' · ');
}
} catch (_) { }
if (lastWrap && lastBox) {
lastWrap.style.display = '';
const href = toLessonHref(book, lesson);
lastBox.innerHTML = `
<a class="last-seen" href="${href}" data-id="${rec.id}" id="lastSeenLink">
<div class="lesson-content">
<div class="lesson-num">上次学习</div>
<div class="lesson-title">${lesson.title}</div>
${posTxt ? `<div style="font-size:13px;color:var(--muted);margin-top:4px">${posTxt}</div>` : ''}
</div>
<div style="flex:0 0 auto;width:20px;height:20px;color:var(--text);display:flex;align-items:center;justify-content:center">→</div>
</a>`;
}
} else {
if (lastWrap && lastBox) { lastWrap.style.display = 'none'; lastBox.innerHTML = ''; }
}
} else {
if (lastWrap && lastBox) { lastWrap.style.display = 'none'; lastBox.innerHTML = ''; }
}
} catch (_) { }
const existingGrid = container.querySelector('.lessons-grid');
if (existingGrid) {
existingGrid.innerHTML = lessons.map((l, i) => itemHTML(book, l, i, favs)).join('');
} else {
const gridDiv = document.createElement('div');
gridDiv.className = 'lessons-grid';
gridDiv.innerHTML = lessons.map((l, i) => itemHTML(book, l, i, favs)).join('');
container.appendChild(gridDiv);
}
}
window.addEventListener('hashchange', load, { passive: true });
NCE_APP.initSegmented(document);
window.toggleFav = function (id) {
if (!id) return;
const favs = getFavs();
if (favs.has(id)) favs.delete(id); else favs.add(id);
saveFavs(favs);
(async () => {
const res = await fetch('static/data.json');
const data = await res.json();
render(data);
})();
};
document.addEventListener('click', (e) => {
const a = e.target.closest('#lastSeenLink');
if (!a) return;
const id = a.dataset.id;
try { sessionStorage.setItem('nce_resume', id); sessionStorage.setItem('nce_resume_play', '1'); } catch (_) { }
});
load();
});
</script>
<style>
.tabs {
display: flex;
gap: 6px;
justify-content: center;
margin: 8px 0
}
</style>
</head>
<body>
<canvas id="bg-canvas"></canvas>
<div class="container">
<header class="hero">
<div class="header-actions">
<button id="searchBtn" class="icon-btn search-trigger" aria-label="搜索">
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round"
stroke-linejoin="round">
<circle cx="11" cy="11" r="8"></circle>
<line x1="21" y1="21" x2="16.65" y2="16.65"></line>
</svg>
</button>
<button id="themeToggleBtn" class="icon-btn theme-toggle" aria-label="切换主题">
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
<path d="M21 12.79A9 9 0 1 1 11.21 3 7 7 0 0 0 21 12.79z"></path>
</svg>
</button>
</div>
<h1 id="bookTitle">NCE Flow</h1>
<p class="subtitle">简约 · 高效 · 专注</p>
<div class="seg-wrap">
<div class="segmented tabs" role="tablist" aria-label="册别">
<a class="seg" href="#NCE1" data-book="NCE1">第一册</a>
<a class="seg" href="#NCE2" data-book="NCE2">第二册</a>
<a class="seg" href="#NCE3" data-book="NCE3">第三册</a>
<a class="seg" href="#NCE4" data-book="NCE4">第四册</a>
<a class="seg" href="favorites.html" id="favoritesLinkHome">清单</a>
</div>
</div>
</header>
<!-- Search Modal -->
<div id="searchModal" class="search-overlay" hidden>
<div class="search-container">
<div class="search-header">
<div class="search-input-wrapper">
<svg class="search-icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
<circle cx="11" cy="11" r="8"></circle>
<line x1="21" y1="21" x2="16.65" y2="16.65"></line>
</svg>
<input type="text" id="searchInput" placeholder="搜索句子、单词或课文..." autocomplete="off">
<button id="searchClear" class="search-clear" hidden>×</button>
</div>
<button id="searchClose" class="search-cancel">取消</button>
</div>
<div class="search-body">
<div id="searchResults" class="search-results"></div>
<div id="searchEmpty" class="search-empty" hidden>
<div class="empty-icon">
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
<circle cx="11" cy="11" r="8"></circle>
<line x1="21" y1="21" x2="16.65" y2="16.65"></line>
</svg>
</div>
<p>未找到相关内容</p>
</div>
<div id="searchLoading" class="search-loading" hidden>
<div class="spinner"></div>
</div>
</div>
</div>
</div>
<main class="lessons" id="lessons">
<section class="section last-seen-section" id="lastSeenWrap" style="display:none">
<div id="lastSeen"></div>
</section>
</main>
<footer>
<p class="repo">
<a class="gh-link" href="https://github.com/luzhenhua/NCE-Flow" target="_blank" rel="noopener"
aria-label="GitHub repository">
<svg viewBox="0 0 16 16" aria-hidden="true" focusable="false">
<path
d="M8 0C3.58 0 0 3.58 0 8c0 3.54 2.29 6.53 5.47 7.59.4.07.55-.17.55-.38 0-.19-.01-.82-.01-1.49-2.01.37-2.53-.49-2.69-.94-.09-.23-.48-.94-.82-1.13-.28-.15-.68-.52-.01-.53.63-.01 1.08.58 1.23.82.72 1.21 1.87.87 2.33.66.07-.52.28-.87.51-1.07-1.78-.2-3.64-.89-3.64-3.95 0-.87.31-1.59.82-2.15-.08-.2-.36-1.02.08-2.12 0 0 .67-.21 2.2.82.64-.18 1.32-.27 2-.27.68 0 1.36.09 2 .27 1.53-1.04 2.2-.82 2.2-.82.44 1.1.16 1.92.08 2.12.51.56.82 1.27.82 2.15 0 3.07-1.87 3.75-3.65 3.95.29.25.54.73.54 1.48 0 1.07-.01 1.93-.01 2.2 0 .21.15.46.55.38A8.013 8.013 0 0 0 16 8c0-4.42-3.58-8-8-8Z">
</path>
</svg>
</a>
</p>
<p class="byline">本网站由 <a href="https://luzhenhua.cn/" target="_blank" rel="noopener">卢振华</a> 开发与维护</p>
<p class="version"><a href="https://github.com/luzhenhua/NCE-Flow/releases" target="_blank" rel="noopener">版本
1.7.8</a><span id="pwaFooterInstall" class="pwa-footer-link" hidden> · <a href="#">安装应用</a></span></p>
<div class="footer-actions">
<a class="footer-btn" href="about.html">关于</a>
</div>
</footer>
</div>
<script>
// Particle Background Animation
(function () {
const cvs = document.getElementById('bg-canvas');
if (!cvs) return;
const ctx = cvs.getContext('2d');
const DPR_CAP = 1.5;
const TARGET_FPS = 30;
const FRAME_MS = 1000 / TARGET_FPS;
const BASE_FRAME_MS = 1000 / 60;
let particles = [];
let lastRenderTs = 0;
function resize() {
const dpr = Math.min(window.devicePixelRatio || 1, DPR_CAP);
cvs.width = Math.floor(innerWidth * dpr);
cvs.height = Math.floor(innerHeight * dpr);
ctx.setTransform(dpr, 0, 0, dpr, 0, 0);
cvs.style.width = innerWidth + 'px';
cvs.style.height = innerHeight + 'px';
}
window.addEventListener('resize', resize);
class Particle {
constructor() {
this.x = Math.random() * innerWidth;
this.y = Math.random() * innerHeight;
this.vx = (Math.random() - .5) * .3;
this.vy = (Math.random() - .5) * .3;
this.r = Math.random() * 1.2 + .5;
}
update(step) {
this.x += this.vx * step;
this.y += this.vy * step;
if (this.x < 0 || this.x > innerWidth) this.vx *= -1;
if (this.y < 0 || this.y > innerHeight) this.vy *= -1;
}
draw() {
ctx.beginPath();
ctx.arc(this.x, this.y, this.r, 0, Math.PI * 2);
ctx.fillStyle = isDark() ? 'rgba(255,255,255,0.4)' : 'rgba(0,0,0,0.25)';
ctx.fill();
}
}
function isDark() {
return document.documentElement.classList.contains('dark-theme') ||
document.body.classList.contains('dark-theme');
}
function drawLines() {
const maxDist = 100;
const maxDistSq = maxDist * maxDist;
for (let i = 0; i < particles.length; i++) {
for (let j = i + 1; j < particles.length; j++) {
const dx = particles[i].x - particles[j].x,
dy = particles[i].y - particles[j].y;
const distSq = dx * dx + dy * dy;
if (distSq < maxDistSq) {
const dist = Math.sqrt(distSq);
ctx.beginPath();
ctx.moveTo(particles[i].x, particles[i].y);
ctx.lineTo(particles[j].x, particles[j].y);
ctx.strokeStyle = isDark()
? `rgba(255,255,255,${1 - dist / maxDist})`
: `rgba(0,0,0,${.5 - dist / (maxDist * 2)})`;
ctx.lineWidth = .5;
ctx.stroke();
}
}
}
}
function init() {
resize();
particles = Array.from({ length: Math.floor(innerWidth * innerHeight / 18000) }, () => new Particle());
requestAnimationFrame(animate);
}
function animate(ts) {
requestAnimationFrame(animate);
if (!lastRenderTs) lastRenderTs = ts;
const elapsed = ts - lastRenderTs;
if (elapsed < FRAME_MS) return;
lastRenderTs = ts - (elapsed % FRAME_MS);
const step = Math.min(elapsed / BASE_FRAME_MS, 5);
ctx.clearRect(0, 0, innerWidth, innerHeight);
particles.forEach(p => { p.update(step); p.draw(); });
drawLines();
}
init();
})();
</script>
<script>
// 注册 Service Worker
if ('serviceWorker' in navigator) {
window.addEventListener('load', () => {
navigator.serviceWorker.register('/sw.js')
.then((reg) => {
console.log('[PWA] Service Worker 注册成功');
reg.update();
if (reg.waiting) {
reg.waiting.postMessage({ type: 'SKIP_WAITING' });
}
reg.addEventListener('updatefound', () => {
const newWorker = reg.installing;
if (!newWorker) return;
newWorker.addEventListener('statechange', () => {
if (newWorker.state === 'installed' && navigator.serviceWorker.controller) {
newWorker.postMessage({ type: 'SKIP_WAITING' });
}
});
});
// Show update notification instead of auto-refresh
navigator.serviceWorker.addEventListener('controllerchange', () => {
showUpdateNotification();
});
})
.catch(err => console.log('[PWA] Service Worker 注册失败:', err));
});
}
function showUpdateNotification() {
// Prevent duplicate notifications
if (document.getElementById('updateNotification')) return;
const notification = document.createElement('div');
notification.id = 'updateNotification';
notification.innerHTML = `
<span>🎉 新版本已就绪</span>
<button onclick="window.location.reload()">点击刷新</button>
`;
notification.style.cssText = `
position: fixed;
bottom: 80px;
left: 50%;
transform: translateX(-50%);
background: var(--text, #1d1d1f);
color: var(--bg, #fff);
padding: 12px 20px;
border-radius: 12px;
display: flex;
align-items: center;
gap: 12px;
box-shadow: 0 4px 20px rgba(0,0,0,0.15);
z-index: 9999;
font-size: 14px;
animation: slideUp 0.3s ease;
`;
notification.querySelector('button').style.cssText = `
background: var(--accent, #3b82f6);
color: #fff;
border: none;
padding: 6px 14px;
border-radius: 8px;
font-size: 13px;
cursor: pointer;
font-weight: 500;
`;
document.body.appendChild(notification);
}
</script>
<!-- PWA Install Prompt -->
<div id="pwaPrompt" class="pwa-prompt">
<img src="icons/icon-192x192.png" alt="" class="pwa-prompt-icon">
<div class="pwa-prompt-content">
<span class="pwa-prompt-title">安装 NCE Flow</span>
<span class="pwa-prompt-sub" id="pwaPromptSub">添加到主屏幕,随时学习</span>
</div>
<button id="pwaInstall" class="pwa-prompt-btn">安装</button>
<span id="pwaClose" class="pwa-prompt-close">×</span>
</div>
<script>
(function () {
const DISMISS_KEY = 'pwa_dismissed';
const INSTALLED_KEY = 'pwa_installed';
let deferredPrompt = null;
const el = document.getElementById('pwaPrompt');
const installBtn = document.getElementById('pwaInstall');
const closeBtn = document.getElementById('pwaClose');
const promptSub = document.getElementById('pwaPromptSub');
const footerInstall = document.getElementById('pwaFooterInstall');
if (!el) return;
// 检测 iOS Safari
const isIOS = /iPad|iPhone|iPod/.test(navigator.userAgent) || (navigator.platform === 'MacIntel' && navigator.maxTouchPoints > 1);
const isSafari = /Safari/.test(navigator.userAgent) && !/Chrome|CriOS|FxiOS/.test(navigator.userAgent);
const isIOSSafari = isIOS && isSafari;
const isStandalone = window.matchMedia('(display-mode:standalone)').matches || navigator.standalone;
const isInstalled = () => isStandalone || localStorage.getItem(INSTALLED_KEY);
const isDismissed = () => { const d = localStorage.getItem(DISMISS_KEY); return d && (Date.now() - parseInt(d)) < 7 * 24 * 60 * 60 * 1000; };
const showPrompt = () => {
if (isInstalled() || isDismissed()) return;
if (!deferredPrompt && !isIOSSafari) return;
el.classList.add('show');
};
const hidePrompt = () => el.classList.remove('show');
const showFooterLink = () => { if (footerInstall && !isInstalled()) footerInstall.hidden = false; };
const hideFooterLink = () => { if (footerInstall) footerInstall.hidden = true; };
// iOS 引导界面
const showIOSGuide = () => {
el.classList.add('ios-prompt');
promptSub.innerHTML = '点击底部 <svg class="ios-icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M4 12v8a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2v-8"/><polyline points="16 6 12 2 8 6"/><line x1="12" y1="2" x2="12" y2="15"/></svg> 然后选择「添加到主屏幕」';
installBtn.textContent = '知道了';
installBtn.onclick = hidePrompt;
};
const doInstall = async () => {
// iOS Safari: 点击后显示引导
if (isIOSSafari) {
showIOSGuide();
return;
}
// Chrome/Edge: 标准安装流程
if (!deferredPrompt) return;
deferredPrompt.prompt();
const { outcome } = await deferredPrompt.userChoice;
if (outcome === 'accepted') localStorage.setItem(INSTALLED_KEY, '1');
deferredPrompt = null;
hidePrompt();
hideFooterLink();
};
// iOS Safari: 延迟显示提示(与 Android 相同的初始界面)
if (isIOSSafari && !isInstalled() && !isDismissed()) {
showFooterLink();
setTimeout(showPrompt, 2500);
}
// Chrome/Edge: 标准安装流程
window.addEventListener('beforeinstallprompt', e => {
e.preventDefault();
deferredPrompt = e;
showFooterLink();
setTimeout(showPrompt, 2500);
});
installBtn.addEventListener('click', doInstall);
if (footerInstall) {
footerInstall.querySelector('a').addEventListener('click', e => {
e.preventDefault();
showPrompt();
});
}
closeBtn.addEventListener('click', () => { localStorage.setItem(DISMISS_KEY, Date.now()); hidePrompt(); });
window.addEventListener('appinstalled', () => { localStorage.setItem(INSTALLED_KEY, '1'); hidePrompt(); hideFooterLink(); });
})();
</script>
<!-- Copyright Confirmation Modal -->
<div id="copyrightModal" class="modal-overlay" style="display: none;">
<div class="modal-card">
<div class="modal-icon">
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
<path d="M12 22s8-4 8-10V5l-8-3-8 3v7c0 6 8 10 8 10z"></path>
</svg>
</div>
<h3 class="modal-title">正版承诺</h3>
<p class="modal-text">本网站仅供新概念英语学习者辅助使用。使用本网站前,请确认您已购买正版新概念英语,拒绝任何形式的盗版书籍。</p>
<div class="modal-checkbox-wrapper">
<input type="checkbox" id="copyrightCheck">
<label for="copyrightCheck">我已购买正版新概念英语书籍</label>
</div>
<button id="copyrightConfirmBtn" class="modal-btn" disabled>进入学习</button>
</div>
</div>
<script>
(function () {
const KEY = 'nce_copyright_confirmed';
const modal = document.getElementById('copyrightModal');
const checkbox = document.getElementById('copyrightCheck');
const btn = document.getElementById('copyrightConfirmBtn');
if (!modal || !checkbox || !btn) return;
// Check if already confirmed
const confirmed = localStorage.getItem(KEY);
if (!confirmed) {
modal.style.display = 'flex';
// Disable scroll
document.body.style.overflow = 'hidden';
}
checkbox.addEventListener('change', (e) => {
btn.disabled = !e.target.checked;
});
btn.addEventListener('click', () => {
if (checkbox.checked) {
localStorage.setItem(KEY, '1');
modal.style.opacity = '0';
setTimeout(() => {
modal.style.display = 'none';
document.body.style.overflow = '';
}, 300);
}
});
})();
</script>
</body>
</html>