Spaces:
Sleeping
Sleeping
Update templates/index.html
Browse files- templates/index.html +32 -18
templates/index.html
CHANGED
@@ -9,7 +9,7 @@
|
|
9 |
<body>
|
10 |
<div class="flashcard" id="flashcard">
|
11 |
<div class="content">
|
12 |
-
<h2>Set: {{ set_name }} ({{ index + 1 }}/{{ total }})</h2>
|
13 |
<p id="card-text"><strong>English:</strong> {{ english }}</p>
|
14 |
<audio controls id="audioPlayer">
|
15 |
<source src="{{ audio_url }}" type="audio/mp3">
|
@@ -26,43 +26,57 @@
|
|
26 |
<script>
|
27 |
const flipBtn = document.getElementById('flipBtn');
|
28 |
let showingEnglish = true;
|
29 |
-
|
30 |
-
const
|
|
|
|
|
|
|
31 |
|
32 |
flipBtn.addEventListener('click', function() {
|
33 |
const cardText = document.getElementById('card-text');
|
34 |
if (showingEnglish) {
|
35 |
-
cardText.innerHTML = japaneseText;
|
36 |
showingEnglish = false;
|
37 |
} else {
|
38 |
-
cardText.innerHTML = englishText;
|
39 |
showingEnglish = true;
|
40 |
}
|
41 |
});
|
42 |
|
43 |
document.getElementById('prevBtn').addEventListener('click', function() {
|
44 |
-
|
|
|
45 |
});
|
46 |
|
47 |
document.getElementById('nextBtn').addEventListener('click', function() {
|
48 |
-
|
|
|
49 |
});
|
50 |
|
51 |
-
function
|
52 |
-
|
53 |
-
newIndex = {{ total }} - 1;
|
54 |
-
} else if (newIndex >= {{ total }}) {
|
55 |
-
newIndex = 0;
|
56 |
-
}
|
57 |
-
|
58 |
-
fetch(`/whereAudio?set=${setName}&index=${newIndex}`)
|
59 |
.then(response => response.json())
|
60 |
.then(data => {
|
|
|
|
|
|
|
|
|
61 |
const audioPlayer = document.getElementById('audioPlayer');
|
62 |
-
|
63 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
64 |
});
|
65 |
}
|
66 |
</script>
|
67 |
</body>
|
68 |
-
</html>
|
|
|
9 |
<body>
|
10 |
<div class="flashcard" id="flashcard">
|
11 |
<div class="content">
|
12 |
+
<h2 id="card-header">Set: {{ set_name }} ({{ index + 1 }}/{{ total }})</h2>
|
13 |
<p id="card-text"><strong>English:</strong> {{ english }}</p>
|
14 |
<audio controls id="audioPlayer">
|
15 |
<source src="{{ audio_url }}" type="audio/mp3">
|
|
|
26 |
<script>
|
27 |
const flipBtn = document.getElementById('flipBtn');
|
28 |
let showingEnglish = true;
|
29 |
+
let currentIndex = {{ index }};
|
30 |
+
const setName = '{{ set_name }}';
|
31 |
+
const total = {{ total }};
|
32 |
+
let englishText = "{{ english }}";
|
33 |
+
let japaneseText = "{{ japanese }}";
|
34 |
|
35 |
flipBtn.addEventListener('click', function() {
|
36 |
const cardText = document.getElementById('card-text');
|
37 |
if (showingEnglish) {
|
38 |
+
cardText.innerHTML = "<strong>Japanese:</strong> " + japaneseText;
|
39 |
showingEnglish = false;
|
40 |
} else {
|
41 |
+
cardText.innerHTML = "<strong>English:</strong> " + englishText;
|
42 |
showingEnglish = true;
|
43 |
}
|
44 |
});
|
45 |
|
46 |
document.getElementById('prevBtn').addEventListener('click', function() {
|
47 |
+
currentIndex = (currentIndex - 1 + total) % total;
|
48 |
+
updateFlashcard(setName, currentIndex);
|
49 |
});
|
50 |
|
51 |
document.getElementById('nextBtn').addEventListener('click', function() {
|
52 |
+
currentIndex = (currentIndex + 1) % total;
|
53 |
+
updateFlashcard(setName, currentIndex);
|
54 |
});
|
55 |
|
56 |
+
function updateFlashcard(setName, newIndex) {
|
57 |
+
fetch(`/flashcards?set=${setName}&index=${newIndex}`)
|
|
|
|
|
|
|
|
|
|
|
|
|
58 |
.then(response => response.json())
|
59 |
.then(data => {
|
60 |
+
englishText = data.english;
|
61 |
+
japaneseText = data.japanese;
|
62 |
+
const cardHeader = document.getElementById('card-header');
|
63 |
+
const cardText = document.getElementById('card-text');
|
64 |
const audioPlayer = document.getElementById('audioPlayer');
|
65 |
+
|
66 |
+
// カード内容を更新
|
67 |
+
cardHeader.innerHTML = `Set: ${setName} (${newIndex + 1}/${total})`;
|
68 |
+
cardText.innerHTML = "<strong>English:</strong> " + englishText;
|
69 |
+
showingEnglish = true;
|
70 |
+
|
71 |
+
// 音声ファイルの更新
|
72 |
+
fetch(`/whereAudio?set=${setName}&index=${newIndex}`)
|
73 |
+
.then(response => response.json())
|
74 |
+
.then(data => {
|
75 |
+
audioPlayer.src = data.audio_url;
|
76 |
+
audioPlayer.play();
|
77 |
+
});
|
78 |
});
|
79 |
}
|
80 |
</script>
|
81 |
</body>
|
82 |
+
</html>
|