-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathday.html
More file actions
452 lines (394 loc) · 20.5 KB
/
day.html
File metadata and controls
452 lines (394 loc) · 20.5 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
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=5.0, user-scalable=yes">
<meta name="description" content="Daily Mandarin Chinese lessons with audio and text - 每日中文课程,配有音频和文本">
<meta name="theme-color" content="#e74c3c">
<meta name="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 - Daily Lesson</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/video-player.css">
<link rel="stylesheet" href="css/native-speaker.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">Day </span><span id="day-number"></span><span class="zh">天</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="#" class="nav-btn" id="prev-btn-top">
<i class="fas fa-arrow-left"></i> <span class="zh">上一天</span><span class="en">Previous Day</span>
</a>
<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>
<a href="#" class="nav-btn" id="next-btn-top">
<span class="zh">下一天</span><span class="en">Next Day</span> <i class="fas fa-arrow-right"></i>
</a>
</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="text-content" id="text-content">
<!-- Text content will be dynamically added here -->
</div>
<!-- Practice with Native Speaker Videos (Mandarin only) -->
<div id="video-section" style="display: none;">
<div class="section-divider"></div>
<h3 class="practice-heading">
<span class="zh">观看视频练习</span>
<span class="en">Watch Practice Videos</span>
</h3>
<div class="video-player">
<iframe id="youtube-video" frameborder="0" allowfullscreen></iframe>
<div id="video-fallback">
<span class="zh">视频暂时无法使用</span>
<span class="en">Video currently unavailable</span>
</div>
</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="#" class="nav-btn" id="prev-btn">
<i class="fas fa-arrow-left"></i> <span class="zh">上一天</span><span class="en">Previous Day</span>
</a>
<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>
<a href="#" class="nav-btn" id="next-btn">
<span class="zh">下一天</span><span class="en">Next Day</span> <i class="fas fa-arrow-right"></i>
</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);
});
});
}
document.addEventListener('DOMContentLoaded', function() {
const urlParams = new URLSearchParams(window.location.search);
const day = parseInt(urlParams.get('day')) || 1;
const lang = urlParams.get('lang') || 'zh';
// Update day number
document.getElementById('day-number').textContent = day;
// Check if day is completed
const completedDays = JSON.parse(localStorage.getItem('completedDays') || '{}');
const completeBtn = document.getElementById('complete-btn');
if (completedDays[`${day}_${lang}`]) {
completeBtn.classList.add('completed');
completeBtn.innerHTML = '<i class="fas fa-check-circle"></i> Completed';
completeBtn.disabled = true;
}
completeBtn.addEventListener('click', () => {
// Mark day as complete
completedDays[`${day}_${lang}`] = true;
localStorage.setItem('completedDays', JSON.stringify(completedDays));
// Update button state
completeBtn.classList.add('completed');
completeBtn.innerHTML = '<i class="fas fa-check-circle"></i> Completed';
completeBtn.disabled = true;
// Calculate total completed days
const totalCompleted = Object.keys(completedDays).filter(key => key.endsWith(`_${lang}`)).length;
// Update progress in localStorage
localStorage.setItem('currentProgress', JSON.stringify({
lang: lang,
completed: totalCompleted
}));
// Update progress on the page
updatePageProgress(lang, totalCompleted);
// Show completion notification
const notification = document.getElementById('copy-notification');
notification.textContent = 'Day 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 to update progress UI
function updatePageProgress(lang, completed) {
// Update day status icons
const dayGrid = document.querySelector('.day-grid');
if (dayGrid) {
const dayLinks = dayGrid.querySelectorAll('a');
dayLinks.forEach((link, index) => {
const day = index + 1;
const status = link.querySelector('.day-status i');
if (completedDays[`${day}_${lang}`]) {
status.className = 'fas fa-check-circle';
status.style.color = 'var(--success-color)';
} else {
status.className = 'fas fa-circle';
status.style.color = 'var(--warning-color)';
}
});
}
// Update progress bar and text if on index page
const progressContainer = document.querySelector('.progress-container');
if (progressContainer) {
const progressText = progressContainer.querySelector('p');
const progressBar = progressContainer.querySelector('.progress-fill');
if (progressText && progressBar) {
progressText.textContent = `Progress: Day ${completed}/40`;
progressBar.style.width = `${(completed / 40) * 100}%`;
}
}
}
// Initialize progress on page load
const initialCompleted = Object.keys(completedDays).filter(key => key.endsWith(`_${lang}`)).length;
updatePageProgress(lang, initialCompleted);
// Set active language
const languageBtns = document.querySelectorAll('.language-btn');
languageBtns.forEach(btn => {
if (btn.dataset.lang === lang) {
btn.classList.add('active');
}
btn.addEventListener('click', () => {
window.location.href = `day.html?day=${day}&lang=${btn.dataset.lang}`;
});
});
// Set language flag
const flagMap = {
'zh': '🇨🇳',
'pinyin': '🔤',
'en': '🇺🇸'
};
document.getElementById('language-flag').textContent = flagMap[lang];
// Show video section only for Mandarin content
const videoSection = document.getElementById('video-section');
videoSection.style.display = lang === 'zh' ? 'block' : 'none';
// Update section info
const sectionInfo = getSectionInfo(day);
document.getElementById('section-title').textContent = sectionInfo.title;
document.getElementById('section-description').textContent = sectionInfo.description;
// Load audio from audio_files directory
const audio = document.getElementById('audio-player');
// For Pinyin, use Mandarin audio. For English and Mandarin, use their respective audio files
const audioLang = lang === 'pinyin' ? 'zh' : lang;
const audioPath = `audio_files/day${day}_${audioLang}.mp3`;
audio.src = audioPath;
// Add a note only for Pinyin that it's using Mandarin audio
const audioFallback = document.getElementById('audio-fallback');
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.innerHTML = '';
audioFallback.style.display = 'none';
}
// Load text content from text_files directory
console.log(`Attempting to load: text_files/day${day}_${lang}.txt`);
fetch(`text_files/day${day}_${lang}.txt`)
.then(response => {
console.log('Response status:', response.status);
if (!response.ok) {
throw new Error(`Network response was not ok: ${response.status}`);
}
return response.text();
})
.then(text => {
console.log('Text loaded successfully, length:', text.length);
console.log('First 100 characters:', text.substring(0, 100));
formatAndDisplayContent(text);
})
.catch(error => {
console.error('Error loading text:', error);
document.getElementById('text-content').innerHTML = '<p class="error">Text content not available.</p>';
});
// Update navigation
const prevBtn = document.getElementById('prev-btn');
const nextBtn = document.getElementById('next-btn');
const prevBtnTop = document.getElementById('prev-btn-top');
const nextBtnTop = document.getElementById('next-btn-top');
if (day > 1) {
prevBtn.href = `day.html?day=${day - 1}&lang=${lang}`;
prevBtnTop.href = `day.html?day=${day - 1}&lang=${lang}`;
} else {
prevBtn.classList.add('disabled');
prevBtnTop.classList.add('disabled');
prevBtn.href = '#';
prevBtnTop.href = '#';
}
if (day < 40) {
nextBtn.href = `day.html?day=${day + 1}&lang=${lang}`;
nextBtnTop.href = `day.html?day=${day + 1}&lang=${lang}`;
} else {
nextBtn.classList.add('disabled');
nextBtnTop.classList.add('disabled');
nextBtn.href = '#';
nextBtnTop.href = '#';
}
});
function formatAndDisplayContent(text) {
console.log('Starting to format content');
// First, normalize line endings and remove any extra whitespace
text = text.replace(/\r\n/g, '\n').replace(/\r/g, '\n');
// Split into sections based on titles (lines ending with multiple dashes)
const sections = text.split(/\n(?=\w[^\n]+\n-+\n)/);
console.log('Number of sections:', sections.length);
const contentDiv = document.getElementById('text-content');
contentDiv.innerHTML = '';
sections.forEach((section, index) => {
console.log(`Processing section ${index + 1}`);
if (section.trim()) {
const lines = section.split('\n');
// Get the title (first line) and remove any trailing dashes
let title = lines[0].replace(/\s*[-]+\s*$/, '').trim();
// Skip empty sections or sections that are just separators
if (!title || /^[-\s]+$/.test(title)) {
return;
}
// Get phrases, skipping empty lines, separator lines, and the line of dashes after the title
let phrases = lines.slice(1).filter(line => {
const trimmed = line.trim();
return trimmed && !/^[-\s]+$/.test(trimmed);
});
const sectionDiv = document.createElement('div');
sectionDiv.className = 'phrase-section';
const titleEl = document.createElement('h3');
titleEl.textContent = title;
sectionDiv.appendChild(titleEl);
const phraseList = document.createElement('div');
phraseList.className = 'phrase-list';
phrases.forEach(phrase => {
if (phrase.trim()) {
const phraseItem = document.createElement('div');
phraseItem.className = 'phrase-item';
const phraseText = document.createElement('span');
phraseText.textContent = phrase.trim();
const copyBtn = document.createElement('button');
copyBtn.className = 'copy-btn';
copyBtn.innerHTML = '<i class="fas fa-copy"></i>';
copyBtn.addEventListener('click', () => copyPhrase(phrase.trim()));
phraseItem.appendChild(phraseText);
phraseItem.appendChild(copyBtn);
phraseList.appendChild(phraseItem);
}
});
sectionDiv.appendChild(phraseList);
contentDiv.appendChild(sectionDiv);
}
});
}
function copyPhrase(phrase) {
navigator.clipboard.writeText(phrase).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);
});
}
function getSectionInfo(day) {
if (day <= 7) {
return {
title: 'Pinyin System & Pronunciation',
description: 'Master the fundamentals of Mandarin pronunciation and tones.'
};
} else if (day <= 14) {
return {
title: 'Essential Daily Phrases',
description: 'Learn practical phrases for everyday communication.'
};
} else if (day <= 22) {
return {
title: 'Cultural Context & Daily Life',
description: 'Understand Chinese culture and daily life communication.'
};
} else if (day <= 30) {
return {
title: 'Professional Mandarin',
description: 'Master business and professional communication.'
};
} else {
return {
title: 'Advanced Fluency',
description: 'Achieve advanced fluency and real-world applications.'
};
}
}
</script>
<script>
// 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>
<script src="js/video-loader.js"></script>
</body>
</html>