CnJaFlashC-1 / templates /index.html
OzoneAsai's picture
Update templates/index.html
99ddf7a verified
raw
history blame
2.85 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>Set: {{ set_name }} ({{ index + 1 }}/{{ total }})</h2>
<p id="card-text"><strong>English:</strong> {{ english }}</p>
<audio controls>
<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;
const englishText = "<strong>English:</strong> {{ english }}";
const japaneseText = "<strong>Japanese:</strong> {{ japanese }}";
flipBtn.addEventListener('click', function() {
const cardText = document.getElementById('card-text');
if (showingEnglish) {
cardText.innerHTML = japaneseText;
showingEnglish = false;
} else {
cardText.innerHTML = englishText;
showingEnglish = true;
}
});
document.getElementById('prevBtn').addEventListener('click', function() {
let newIndex = {{ index }} - 1;
if (newIndex < 0) {
newIndex = {{ total }} - 1;
}
navigate('{{ url_for("index") }}?set={{ set_name }}&index=' + newIndex);
});
document.getElementById('nextBtn').addEventListener('click', function() {
let newIndex = {{ index }} + 1;
if (newIndex >= {{ total }}) {
newIndex = 0;
}
navigate('{{ url_for("index") }}?set={{ set_name }}&index=' + newIndex);
});
function navigate(url) {
const flashcard = document.getElementById('flashcard');
animateFadeOut(flashcard, function() {
window.location.href = url;
});
}
function animateFadeOut(element, callback) {
let opacity = 1;
function fade() {
opacity -= 0.1;
if (opacity <= 0) {
element.style.opacity = 0;
callback();
} else {
element.style.opacity = opacity;
requestAnimationFrame(fade);
}
}
fade();
}
</script>
</body>
</html>