Spaces:
Sleeping
Sleeping
| <html lang="en"> | |
| <head> | |
| <meta charset="UTF-8"> | |
| <meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
| <title>Flashcards</title> | |
| <link rel="stylesheet" href="{{ url_for('static', filename='style.css') }}"> | |
| </head> | |
| <body> | |
| <div class="flashcard" id="flashcard"> | |
| <div class="content"> | |
| <h2 id="card-header">Set: {{ set_name }} ({{ index + 1 }}/{{ total }})</h2> | |
| <p id="card-text"><strong>English:</strong> {{ english }}</p> | |
| <audio controls id="audioPlayer"> | |
| <source src="{{ audio_url }}" type="audio/mp3"> | |
| Your browser does not support the audio element. | |
| </audio> | |
| </div> | |
| <div class="navigation"> | |
| <button id="prevBtn">Previous</button> | |
| <button id="flipBtn">Flip</button> | |
| <button id="nextBtn">Next</button> | |
| </div> | |
| </div> | |
| <script> | |
| let showingEnglish = true; | |
| let currentIndex = {{ index }}; | |
| const setName = '{{ set_name }}'; | |
| let total = {{ total }}; | |
| const flipBtn = document.getElementById('flipBtn'); | |
| let englishText = "{{ english }}"; | |
| let japaneseText = "{{ japanese }}"; | |
| // フリップボタンで英語と日本語の表示を切り替え | |
| flipBtn.addEventListener('click', function() { | |
| const cardText = document.getElementById('card-text'); | |
| if (showingEnglish) { | |
| cardText.innerHTML = "<strong>Japanese:</strong> " + japaneseText; | |
| showingEnglish = false; | |
| } else { | |
| cardText.innerHTML = "<strong>English:</strong> " + englishText; | |
| showingEnglish = true; | |
| } | |
| }); | |
| // Previous ボタンでインデックスを更新 | |
| document.getElementById('prevBtn').addEventListener('click', function() { | |
| currentIndex = (currentIndex - 1 + total) % total; | |
| updateFlashcard(setName, currentIndex); | |
| }); | |
| // Next ボタンでインデックスを更新 | |
| document.getElementById('nextBtn').addEventListener('click', function() { | |
| currentIndex = (currentIndex + 1) % total; | |
| updateFlashcard(setName, currentIndex); | |
| }); | |
| // フラッシュカードの内容を更新 | |
| function updateFlashcard(setName, newIndex) { | |
| fetch(`/flashcards?set=${setName}&index=${newIndex}`) | |
| .then(response => response.json()) | |
| .then(data => { | |
| englishText = data.english; | |
| japaneseText = data.japanese; | |
| const cardHeader = document.getElementById('card-header'); | |
| const cardText = document.getElementById('card-text'); | |
| const audioPlayer = document.getElementById('audioPlayer'); | |
| // カード内容の更新 | |
| cardHeader.innerHTML = `Set: ${data.set_name} (${data.index + 1}/${data.total})`; | |
| cardText.innerHTML = "<strong>English:</strong> " + englishText; | |
| showingEnglish = true; | |
| // 音声ファイルの更新 | |
| audioPlayer.src = data.audio_url; | |
| audioPlayer.play(); | |
| // URLを更新して履歴に残す (リロードしても正しいカードが表示されるように) | |
| history.pushState(null, '', `/flashcards?set=${data.set_name}&index=${data.index}`); | |
| }); | |
| } | |
| // ブラウザの「戻る」ボタンなどに対応 | |
| window.addEventListener('popstate', function() { | |
| const urlParams = new URLSearchParams(window.location.search); | |
| const setName = urlParams.get('set') || 'A'; | |
| const index = parseInt(urlParams.get('index')) || 0; | |
| updateFlashcard(setName, index); | |
| }); | |
| </script> | |
| </body> | |
| </html> |