Spaces:
Sleeping
Sleeping
Update templates/index.html
Browse files- templates/index.html +17 -45
templates/index.html
CHANGED
@@ -11,7 +11,7 @@
|
|
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>
|
15 |
<source src="{{ audio_url }}" type="audio/mp3">
|
16 |
Your browser does not support the audio element.
|
17 |
</audio>
|
@@ -22,22 +22,8 @@
|
|
22 |
<button id="nextBtn">Next</button>
|
23 |
</div>
|
24 |
</div>
|
25 |
-
<script>
|
26 |
-
// Flashcardのズームを調整
|
27 |
-
function adjustFlashcardScale() {
|
28 |
-
const flashcard = document.getElementById('flashcard');
|
29 |
-
const windowWidth = window.innerWidth;
|
30 |
-
const flashcardWidth = flashcard.offsetWidth;
|
31 |
-
|
32 |
-
// スケールを計算して適用
|
33 |
-
const scale = windowWidth / flashcardWidth-0.2;
|
34 |
-
flashcard.style.transform = `scale(${scale})`;
|
35 |
-
}
|
36 |
-
|
37 |
-
// ページロード時とリサイズ時にスケールを適用
|
38 |
-
window.addEventListener('load', adjustFlashcardScale);
|
39 |
-
window.addEventListener('resize', adjustFlashcardScale);
|
40 |
|
|
|
41 |
const flipBtn = document.getElementById('flipBtn');
|
42 |
let showingEnglish = true;
|
43 |
const englishText = "<strong>English:</strong> {{ english }}";
|
@@ -55,41 +41,27 @@
|
|
55 |
});
|
56 |
|
57 |
document.getElementById('prevBtn').addEventListener('click', function() {
|
58 |
-
|
59 |
-
if (newIndex < 0) {
|
60 |
-
newIndex = {{ total }} - 1;
|
61 |
-
}
|
62 |
-
navigate('{{ url_for("index") }}?set={{ set_name }}&index=' + newIndex);
|
63 |
});
|
64 |
|
65 |
document.getElementById('nextBtn').addEventListener('click', function() {
|
66 |
-
|
67 |
-
if (newIndex >= {{ total }}) {
|
68 |
-
newIndex = 0;
|
69 |
-
}
|
70 |
-
navigate('{{ url_for("index") }}?set={{ set_name }}&index=' + newIndex);
|
71 |
});
|
72 |
|
73 |
-
function
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
}
|
79 |
-
|
80 |
-
function animateFadeOut(element, callback) {
|
81 |
-
let opacity = 1;
|
82 |
-
function fade() {
|
83 |
-
opacity -= 0.1;
|
84 |
-
if (opacity <= 0) {
|
85 |
-
element.style.opacity = 0;
|
86 |
-
callback();
|
87 |
-
} else {
|
88 |
-
element.style.opacity = opacity;
|
89 |
-
requestAnimationFrame(fade);
|
90 |
-
}
|
91 |
}
|
92 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
93 |
}
|
94 |
</script>
|
95 |
</body>
|
|
|
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">
|
16 |
Your browser does not support the audio element.
|
17 |
</audio>
|
|
|
22 |
<button id="nextBtn">Next</button>
|
23 |
</div>
|
24 |
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
25 |
|
26 |
+
<script>
|
27 |
const flipBtn = document.getElementById('flipBtn');
|
28 |
let showingEnglish = true;
|
29 |
const englishText = "<strong>English:</strong> {{ english }}";
|
|
|
41 |
});
|
42 |
|
43 |
document.getElementById('prevBtn').addEventListener('click', function() {
|
44 |
+
updateAudio('{{ set_name }}', {{ index }} - 1);
|
|
|
|
|
|
|
|
|
45 |
});
|
46 |
|
47 |
document.getElementById('nextBtn').addEventListener('click', function() {
|
48 |
+
updateAudio('{{ set_name }}', {{ index }} + 1);
|
|
|
|
|
|
|
|
|
49 |
});
|
50 |
|
51 |
+
function updateAudio(setName, newIndex) {
|
52 |
+
if (newIndex < 0) {
|
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 |
+
audioPlayer.src = data.audio_url;
|
63 |
+
audioPlayer.play();
|
64 |
+
});
|
65 |
}
|
66 |
</script>
|
67 |
</body>
|