-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreading.html
More file actions
544 lines (472 loc) · 25.6 KB
/
reading.html
File metadata and controls
544 lines (472 loc) · 25.6 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
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
<meta name="description" content="Mandarin Chinese reading practice - 中文阅读练习">
<meta name="theme-color" content="#e74c3c">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent">
<meta name="apple-mobile-web-app-title" content="Mandarin Pathways">
<title>Mandarin Pathways - Reading Practice</title>
<link rel="manifest" href="manifest.json">
<link rel="apple-touch-icon" href="icons/icon-192x192.png">
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Poppins:wght@400;500;600;700&display=swap" rel="stylesheet">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css">
<link rel="stylesheet" href="css/styles.css">
<link rel="stylesheet" href="css/reading.css">
</head>
<body>
<header>
<h1>Mandarin Pathways</h1>
<p><span class="zh">开启您的中文学习之旅</span><span class="en">Your Journey to Chinese Language Mastery</span></p>
</header>
<main>
<!-- Return to top button -->
<div class="return-to-top" id="returnToTop">
<i class="fas fa-arrow-up"></i>
</div>
<!-- Visual anchor pattern -->
<div class="visual-anchor" style="top: 5%; right: 5%;"></div>
<div class="lesson-container">
<div class="lesson-header">
<div class="lesson-title">
<span class="flag" id="language-flag"></span>
<h2><span class="zh">阅读练习:</span><span class="en">Reading Practice: </span><span id="reading-level"></span></h2>
</div>
<div class="language-selector">
<button class="language-btn" data-lang="zh"><span class="flag">🇨🇳</span> 简体中文</button>
<button class="language-btn" data-lang="pinyin"><span class="flag">🔤</span> Pinyin</button>
<button class="language-btn" data-lang="en"><span class="flag">🇺🇸</span> English</button>
</div>
</div>
<div class="navigation">
<a href="index.html" class="home-btn">
<i class="fas fa-home"></i> <span class="zh">返回首页</span><span class="en">Back to Home</span>
</a>
</div>
<div class="level-selector">
<h3><span class="zh">选择难度级别</span><span class="en">Select Difficulty Level</span></h3>
<div class="level-buttons">
<button class="level-btn" data-level="beginner">
<i class="fas fa-star"></i> <span class="zh">初级</span><span class="en">Beginner</span>
</button>
<button class="level-btn" data-level="intermediate">
<i class="fas fa-star"></i><i class="fas fa-star"></i> <span class="zh">中级</span><span class="en">Intermediate</span>
</button>
<button class="level-btn" data-level="advanced">
<i class="fas fa-star"></i><i class="fas fa-star"></i><i class="fas fa-star"></i> <span class="zh">高级</span><span class="en">Advanced</span>
</button>
</div>
</div>
<div class="topic-selector" style="display: none;">
<h3><span class="zh">选择阅读主题</span><span class="en">Select Reading Topic</span></h3>
<div class="topic-buttons" id="topic-buttons">
<!-- Topics will be dynamically added here based on level -->
</div>
</div>
<div class="section-info">
<h3 id="section-title"></h3>
<p id="section-description"></p>
</div>
<div class="audio-player">
<audio controls id="audio-player" type="audio/mpeg">
<span class="zh">您的浏览器不支持音频元素。</span><span class="en">Your browser does not support the audio element.</span>
</audio>
<div id="audio-fallback"></div>
</div>
<div class="reading-content" id="reading-content">
<!-- Reading content will be dynamically added here -->
</div>
<div class="vocabulary-section" id="vocabulary-section">
<h3><span class="zh">生词表</span><span class="en">Vocabulary</span></h3>
<div class="vocabulary-list" id="vocabulary-list">
<!-- Vocabulary will be dynamically added here -->
</div>
</div>
<div class="questions-section" id="questions-section">
<h3><span class="zh">理解问题</span><span class="en">Comprehension Questions</span></h3>
<div class="questions-list" id="questions-list">
<!-- Questions will be dynamically added here -->
</div>
</div>
<div class="lesson-actions">
<button id="complete-btn" class="complete-btn">
<i class="fas fa-check"></i> <span class="zh">标记为已完成</span><span class="en">Mark as Complete</span>
</button>
</div>
<!-- Section divider with visual anchor -->
<div class="section-divider"></div>
<div class="navigation">
<a href="index.html" class="home-btn">
<i class="fas fa-home"></i> <span class="zh">返回首页</span><span class="en">Back to Home</span>
</a>
</div>
</div>
<!-- Visual anchor pattern -->
<div class="visual-anchor" style="bottom: 10%; left: 5%;"></div>
</main>
<footer>
<p>© 2025 Mandarin Pathways | <span class="zh">赋能中文学习</span><span class="en">Empowering Chinese Language Learning</span></p>
</footer>
<div class="copy-notification" id="copy-notification">
<span class="zh">短语已复制到剪贴板!</span><span class="en">Phrase copied to clipboard!</span>
</div>
<script>
// Register Service Worker
if ('serviceWorker' in navigator) {
window.addEventListener('load', () => {
navigator.serviceWorker.register('/sw.js')
.then(registration => {
console.log('ServiceWorker registration successful');
})
.catch(err => {
console.log('ServiceWorker registration failed: ', err);
});
});
}
// Reading content data structure
const readingData = {
beginner: {
"Self Introduction": {
title: "Self Introduction",
description: "A simple self-introduction in Mandarin",
hasAudio: true
},
"Daily Routine": {
title: "Daily Routine",
description: "Learn vocabulary related to daily activities",
hasAudio: true
}
},
intermediate: {
"At the Restaurant": {
title: "At the Restaurant",
description: "Vocabulary and phrases for dining out",
hasAudio: true
},
"Weekend Plans": {
title: "Weekend Plans",
description: "Discussing weekend activities and plans",
hasAudio: true
}
},
advanced: {
"Environmental Protection": {
title: "Environmental Protection",
description: "Advanced vocabulary related to environmental issues",
hasAudio: true
}
}
};
document.addEventListener('DOMContentLoaded', function() {
const urlParams = new URLSearchParams(window.location.search);
const level = urlParams.get('level') || '';
const topic = urlParams.get('topic') || '';
const lang = urlParams.get('lang') || 'zh';
// Set active language and update HTML lang attribute
const languageBtns = document.querySelectorAll('.language-btn');
languageBtns.forEach(btn => {
if (btn.dataset.lang === lang) {
btn.classList.add('active');
// Set HTML lang attribute based on selected language
if (lang === 'en') {
document.documentElement.setAttribute('lang', 'en');
} else if (lang === 'zh') {
document.documentElement.setAttribute('lang', 'zh-CN');
} else {
// For pinyin, we'll use English as the base language
document.documentElement.setAttribute('lang', 'en');
}
}
btn.addEventListener('click', () => {
const currentLevel = urlParams.get('level') || '';
const currentTopic = urlParams.get('topic') || '';
let newUrl = `reading.html?lang=${btn.dataset.lang}`;
if (currentLevel) {
newUrl += `&level=${currentLevel}`;
if (currentTopic) {
newUrl += `&topic=${currentTopic}`;
}
}
window.location.href = newUrl;
});
});
// Set language flag
const flagMap = {
'zh': '🇨🇳',
'pinyin': '🔤',
'en': '🇺🇸'
};
document.getElementById('language-flag').textContent = flagMap[lang];
// Set up level buttons
const levelBtns = document.querySelectorAll('.level-btn');
levelBtns.forEach(btn => {
if (btn.dataset.level === level) {
btn.classList.add('active');
}
btn.addEventListener('click', () => {
window.location.href = `reading.html?level=${btn.dataset.level}&lang=${lang}`;
});
});
// If level is selected, show topics
if (level && readingData[level]) {
document.querySelector('.topic-selector').style.display = 'block';
document.getElementById('reading-level').textContent = level.charAt(0).toUpperCase() + level.slice(1);
// Populate topics
const topicButtons = document.getElementById('topic-buttons');
topicButtons.innerHTML = '';
Object.keys(readingData[level]).forEach(topicName => {
const btn = document.createElement('button');
btn.className = 'topic-btn';
if (topicName === topic) {
btn.classList.add('active');
}
btn.dataset.topic = topicName;
const icon = document.createElement('i');
icon.className = 'fas fa-book';
btn.appendChild(icon);
const space = document.createTextNode(' ');
btn.appendChild(space);
const text = document.createTextNode(topicName);
btn.appendChild(text);
btn.addEventListener('click', () => {
window.location.href = `reading.html?level=${level}&topic=${topicName}&lang=${lang}`;
});
topicButtons.appendChild(btn);
});
}
// If both level and topic are selected, load content
if (level && topic && readingData[level] && readingData[level][topic]) {
loadReadingContent(level, topic, lang);
} else {
// Hide content sections if no topic selected
document.getElementById('section-title').textContent = '';
document.getElementById('section-description').textContent = '';
document.querySelector('.audio-player').style.display = 'none';
document.getElementById('reading-content').innerHTML = '';
document.getElementById('vocabulary-section').style.display = 'none';
document.getElementById('questions-section').style.display = 'none';
document.getElementById('complete-btn').style.display = 'none';
}
// Mark as complete functionality
const completeBtn = document.getElementById('complete-btn');
const completedReadings = JSON.parse(localStorage.getItem('completedReadings') || '{}');
if (level && topic && completedReadings[`${level}_${topic}_${lang}`]) {
completeBtn.classList.add('completed');
completeBtn.innerHTML = '<i class="fas fa-check-circle"></i> Completed';
completeBtn.disabled = true;
}
completeBtn.addEventListener('click', () => {
if (level && topic) {
// Mark reading as complete
completedReadings[`${level}_${topic}_${lang}`] = true;
localStorage.setItem('completedReadings', JSON.stringify(completedReadings));
// Update button state
completeBtn.classList.add('completed');
completeBtn.innerHTML = '<i class="fas fa-check-circle"></i> Completed';
completeBtn.disabled = true;
// Show completion notification
const notification = document.getElementById('copy-notification');
notification.textContent = 'Reading marked as complete!';
notification.style.display = 'block';
notification.style.animation = 'none';
notification.offsetHeight; // Trigger reflow
notification.style.animation = 'fadeInOut 2s ease';
setTimeout(() => {
notification.style.display = 'none';
notification.textContent = 'Phrase copied to clipboard!';
}, 2000);
}
});
});
function loadReadingContent(level, topic, lang) {
const topicInfo = readingData[level][topic];
// Set section info
document.getElementById('section-title').textContent = topicInfo.title;
document.getElementById('section-description').textContent = topicInfo.description;
// Show content sections
document.querySelector('.audio-player').style.display = 'block';
document.getElementById('vocabulary-section').style.display = 'block';
document.getElementById('questions-section').style.display = 'block';
document.getElementById('complete-btn').style.display = 'block';
// Load audio if available
const audio = document.getElementById('audio-player');
const audioFallback = document.getElementById('audio-fallback');
if (topicInfo.hasAudio) {
// For Pinyin, use Mandarin audio file
const audioLang = lang === 'pinyin' ? 'zh' : lang;
const audioPath = `audio_files/reading/${level}_${topic.toLowerCase().replace(/ /g, '_')}_${audioLang}.mp3`;
audio.src = audioPath;
// Add a note only for Pinyin that it's using Mandarin audio
if (lang === 'pinyin') {
audioFallback.innerHTML = '<p class="note"><i class="fas fa-info-circle"></i> Using Mandarin audio for reference.</p>';
audioFallback.style.display = 'block';
} else {
audioFallback.style.display = 'none';
}
} else {
audio.src = '';
audioFallback.innerHTML = '<p class="note"><i class="fas fa-info-circle"></i> Audio not available for this reading.</p>';
audioFallback.style.display = 'block';
}
// Load text content
fetch(`reading_files/${level}_${topic.toLowerCase().replace(/ /g, '_')}_${lang}.txt`)
.then(response => {
if (!response.ok) {
throw new Error(`Network response was not ok: ${response.status}`);
}
return response.text();
})
.then(text => {
formatAndDisplayReadingContent(text);
})
.catch(error => {
console.error('Error loading reading content:', error);
document.getElementById('reading-content').innerHTML = '<p class="error">Reading content not available. Please try another topic or language.</p>';
document.getElementById('vocabulary-section').style.display = 'none';
document.getElementById('questions-section').style.display = 'none';
});
}
function formatAndDisplayReadingContent(text) {
// Split the text into sections (main text, vocabulary, questions)
const sections = text.split(/\n(?=\w[^\n]+\n-+\n)/);
if (sections.length >= 1) {
// Main reading text
const mainTextSection = sections[0];
const mainTextLines = mainTextSection.split('\n');
// Skip title and separator lines
const mainText = mainTextLines.slice(2).join('\n');
const readingContentDiv = document.getElementById('reading-content');
readingContentDiv.innerHTML = '';
const textParagraphs = mainText.split('\n\n');
textParagraphs.forEach(paragraph => {
if (paragraph.trim()) {
const p = document.createElement('p');
p.textContent = paragraph.trim();
readingContentDiv.appendChild(p);
}
});
}
if (sections.length >= 2) {
// Vocabulary section
const vocabSection = sections[1];
const vocabLines = vocabSection.split('\n');
// Skip title and separator lines
const vocabItems = vocabLines.slice(2).filter(line => line.trim());
const vocabListDiv = document.getElementById('vocabulary-list');
vocabListDiv.innerHTML = '';
vocabItems.forEach(item => {
if (item.trim()) {
const vocabItem = document.createElement('div');
vocabItem.className = 'vocab-item';
// Parse the item to extract the parts (bullet point, word, pinyin, translation)
// Format: • word (pinyin) - translation
const itemText = document.createElement('span');
itemText.innerHTML = item.trim()
.replace(/•/, '<span class="bullet">•</span>')
.replace(/\(([^)]+)\)/, '<span class="pinyin">($1)</span>')
.replace(/-/, '<span class="separator">-</span>');
const copyBtn = document.createElement('button');
copyBtn.className = 'copy-btn';
copyBtn.innerHTML = '<i class="fas fa-copy"></i>';
copyBtn.addEventListener('click', () => copyText(item.trim()));
vocabItem.appendChild(itemText);
vocabItem.appendChild(copyBtn);
vocabListDiv.appendChild(vocabItem);
}
});
} else {
document.getElementById('vocabulary-section').style.display = 'none';
}
if (sections.length >= 3) {
// Questions section
const questionsSection = sections[2];
const questionLines = questionsSection.split('\n');
// Skip title and separator lines
const questions = questionLines.slice(2).filter(line => line.trim());
const questionsListDiv = document.getElementById('questions-list');
questionsListDiv.innerHTML = '';
// Group questions and answers (every two lines)
const questionAnswerPairs = [];
for (let i = 0; i < questions.length; i += 2) {
if (questions[i] && questions[i].trim()) {
const questionText = questions[i].trim();
const answerText = (i + 1 < questions.length) ? questions[i + 1].trim() : '';
questionAnswerPairs.push({ question: questionText, answer: answerText });
}
}
questionAnswerPairs.forEach(pair => {
const questionItem = document.createElement('div');
questionItem.className = 'question-item';
// Parse the question to extract the question number and text
// Format: 【Question #】 Question text
const questionText = document.createElement('p');
questionText.className = 'question-text';
questionText.innerHTML = pair.question
.replace(/【([^】]+)】/, '<span class="question-number">【$1】</span>');
// Create answer section with toggle functionality
const answerSection = document.createElement('div');
answerSection.className = 'answer-section';
const answerInput = document.createElement('textarea');
answerInput.className = 'answer-input';
answerInput.placeholder = 'Write your answer here...';
const answerToggle = document.createElement('button');
answerToggle.className = 'answer-toggle';
answerToggle.innerHTML = '<i class="fas fa-eye"></i> Show Answer';
const answerText = document.createElement('div');
answerText.className = 'answer-text';
answerText.textContent = pair.answer.replace(/^答案: |^Answer: /, '');
answerText.style.display = 'none';
answerToggle.addEventListener('click', () => {
if (answerText.style.display === 'none') {
answerText.style.display = 'block';
answerToggle.innerHTML = '<i class="fas fa-eye-slash"></i> Hide Answer';
} else {
answerText.style.display = 'none';
answerToggle.innerHTML = '<i class="fas fa-eye"></i> Show Answer';
}
});
answerSection.appendChild(answerInput);
answerSection.appendChild(answerToggle);
answerSection.appendChild(answerText);
questionItem.appendChild(questionText);
questionItem.appendChild(answerSection);
questionsListDiv.appendChild(questionItem);
});
} else {
document.getElementById('questions-section').style.display = 'none';
}
}
function copyText(text) {
navigator.clipboard.writeText(text).then(() => {
const notification = document.getElementById('copy-notification');
notification.style.display = 'block';
notification.style.animation = 'none';
notification.offsetHeight; // Trigger reflow
notification.style.animation = 'fadeInOut 2s ease';
setTimeout(() => {
notification.style.display = 'none';
}, 2000);
});
}
// Return to top functionality
window.addEventListener('scroll', function() {
const returnToTop = document.getElementById('returnToTop');
if (window.scrollY > 500) {
returnToTop.classList.add('visible');
} else {
returnToTop.classList.remove('visible');
}
});
document.getElementById('returnToTop').addEventListener('click', function() {
window.scrollTo({
top: 0,
behavior: 'smooth'
});
});
</script>
</body>
</html>