Download script.js from Ethhhnbv/mandarin-magic-presenter: direct link, hf CLI and curl.
- Browser
- Download file 2.47 kB
-
https://huggingface.co/spaces/Ethhhnbv/mandarin-magic-presenter/resolve/main/script.js
- Command line
-
hf download hf://spaces/Ethhhnbv/mandarin-magic-presenter/script.js
-
curl -L -o script.js https://huggingface.co/spaces/Ethhhnbv/mandarin-magic-presenter/resolve/main/script.js
2.47 kB
| class LessonManager { | |
| constructor() { | |
| this.lessons = JSON.parse(localStorage.getItem('lessons')) || []; | |
| this.currentLessonIndex = 0; | |
| this.currentSlideIndex = 0; | |
| } | |
| saveLessons() { | |
| localStorage.setItem('lessons', JSON.stringify(this.lessons)); | |
| } | |
| addLesson(title) { | |
| const newLesson = { | |
| id: Date.now(), | |
| title: title || `New Lesson ${this.lessons.length + 1}`, | |
| slides: [this.createNewSlide()] | |
| }; | |
| this.lessons.push(newLesson); | |
| this.saveLessons(); | |
| return newLesson; | |
| } | |
| createNewSlide() { | |
| return { | |
| id: Date.now(), | |
| title: 'New Slide', | |
| content: '', | |
| notes: '', | |
| pinyin: '', | |
| translation: '', | |
| characters: '' | |
| }; | |
| } | |
| addSlide(lessonIndex) { | |
| const newSlide = this.createNewSlide(); | |
| this.lessons[lessonIndex].slides.push(newSlide); | |
| this.saveLessons(); | |
| return newSlide; | |
| } | |
| updateSlide(lessonIndex, slideIndex, data) { | |
| const slide = this.lessons[lessonIndex].slides[slideIndex]; | |
| Object.assign(slide, data); | |
| this.saveLessons(); | |
| } | |
| deleteSlide(lessonIndex, slideIndex) { | |
| this.lessons[lessonIndex].slides.splice(slideIndex, 1); | |
| this.saveLessons(); | |
| } | |
| deleteLesson(lessonIndex) { | |
| this.lessons.splice(lessonIndex, 1); | |
| this.saveLessons(); | |
| } | |
| } | |
| // Initialize speech recognition | |
| function initSpeechRecognition(lang = 'cmn-Hans-CN') { | |
| const recognition = new (window.SpeechRecognition || window.webkitSpeechRecognition)(); | |
| recognition.lang = lang; | |
| recognition.interimResults = true; | |
| return recognition; | |
| } | |
| // Fullscreen slide functionality | |
| function toggleFullscreenSlide(slideElement) { | |
| if (!document.fullscreenElement) { | |
| slideElement.classList.add('fullscreen-slide'); | |
| slideElement.requestFullscreen().catch(err => { | |
| console.error(`Error attempting to enable fullscreen: ${err.message}`); | |
| }); | |
| } else { | |
| document.exitFullscreen(); | |
| slideElement.classList.remove('fullscreen-slide'); | |
| } | |
| } | |
| // Initialize the app | |
| document.addEventListener('DOMContentLoaded', () => { | |
| const lessonManager = new LessonManager(); | |
| window.lessonManager = lessonManager; // Make it globally available | |
| // Event listeners will be handled by the web components | |
| }); |