CnJaFlashC-1 / templates /index.html
OzoneAsai's picture
Update templates/index.html
28b33ff verified
raw
history blame
3.32 kB
<!DOCTYPE html>
<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>
const flipBtn = document.getElementById('flipBtn');
let showingEnglish = true;
let currentIndex = {{ index }};
const setName = '{{ set_name }}';
const total = {{ total }};
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;
}
});
document.getElementById('prevBtn').addEventListener('click', function() {
currentIndex = (currentIndex - 1 + total) % total;
updateFlashcard(setName, currentIndex);
});
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: ${setName} (${newIndex + 1}/${total})`;
cardText.innerHTML = "<strong>English:</strong> " + englishText;
showingEnglish = true;
// 音声ファイルの更新
fetch(`/whereAudio?set=${setName}&index=${newIndex}`)
.then(response => response.json())
.then(data => {
audioPlayer.src = data.audio_url;
audioPlayer.play();
});
});
}
</script>
</body>
</html>