Spaces:
Sleeping
Sleeping
Update templates/index.html
Browse files- templates/index.html +47 -16
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">
|
|
@@ -24,11 +24,15 @@
|
|
| 24 |
</div>
|
| 25 |
|
| 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) {
|
|
@@ -40,22 +44,49 @@
|
|
| 40 |
}
|
| 41 |
});
|
| 42 |
|
| 43 |
-
// Previous
|
| 44 |
document.getElementById('prevBtn').addEventListener('click', function() {
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
newIndex = {{ total }} - 1;
|
| 48 |
-
}
|
| 49 |
-
window.location.href = `/flashcards?set={{ set_name }}&index=` + newIndex;
|
| 50 |
});
|
| 51 |
|
| 52 |
-
// Next
|
| 53 |
document.getElementById('nextBtn').addEventListener('click', function() {
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 59 |
});
|
| 60 |
</script>
|
| 61 |
</body>
|
|
|
|
| 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">
|
|
|
|
| 24 |
</div>
|
| 25 |
|
| 26 |
<script>
|
|
|
|
| 27 |
let showingEnglish = true;
|
| 28 |
+
let currentIndex = {{ index }};
|
| 29 |
+
const setName = '{{ set_name }}';
|
| 30 |
+
let total = {{ total }};
|
| 31 |
+
const flipBtn = document.getElementById('flipBtn');
|
| 32 |
+
let englishText = "{{ english }}";
|
| 33 |
+
let japaneseText = "{{ japanese }}";
|
| 34 |
|
| 35 |
+
// フリップボタンで英語と日本語の表示を切り替え
|
| 36 |
flipBtn.addEventListener('click', function() {
|
| 37 |
const cardText = document.getElementById('card-text');
|
| 38 |
if (showingEnglish) {
|
|
|
|
| 44 |
}
|
| 45 |
});
|
| 46 |
|
| 47 |
+
// Previous ボタンでインデックスを更新
|
| 48 |
document.getElementById('prevBtn').addEventListener('click', function() {
|
| 49 |
+
currentIndex = (currentIndex - 1 + total) % total;
|
| 50 |
+
updateFlashcard(setName, currentIndex);
|
|
|
|
|
|
|
|
|
|
| 51 |
});
|
| 52 |
|
| 53 |
+
// Next ボタンでインデックスを更新
|
| 54 |
document.getElementById('nextBtn').addEventListener('click', function() {
|
| 55 |
+
currentIndex = (currentIndex + 1) % total;
|
| 56 |
+
updateFlashcard(setName, currentIndex);
|
| 57 |
+
});
|
| 58 |
+
|
| 59 |
+
// フラッシュカードの内容を更新
|
| 60 |
+
function updateFlashcard(setName, newIndex) {
|
| 61 |
+
fetch(`/flashcards?set=${setName}&index=${newIndex}`)
|
| 62 |
+
.then(response => response.json())
|
| 63 |
+
.then(data => {
|
| 64 |
+
englishText = data.english;
|
| 65 |
+
japaneseText = data.japanese;
|
| 66 |
+
const cardHeader = document.getElementById('card-header');
|
| 67 |
+
const cardText = document.getElementById('card-text');
|
| 68 |
+
const audioPlayer = document.getElementById('audioPlayer');
|
| 69 |
+
|
| 70 |
+
// カード内容の更新
|
| 71 |
+
cardHeader.innerHTML = `Set: ${data.set_name} (${data.index + 1}/${data.total})`;
|
| 72 |
+
cardText.innerHTML = "<strong>English:</strong> " + englishText;
|
| 73 |
+
showingEnglish = true;
|
| 74 |
+
|
| 75 |
+
// 音声ファイルの更新
|
| 76 |
+
audioPlayer.src = data.audio_url;
|
| 77 |
+
audioPlayer.play();
|
| 78 |
+
|
| 79 |
+
// URLを更新して履歴に残す (リロードしても正しいカードが表示されるように)
|
| 80 |
+
history.pushState(null, '', `/flashcards?set=${data.set_name}&index=${data.index}`);
|
| 81 |
+
});
|
| 82 |
+
}
|
| 83 |
+
|
| 84 |
+
// ブラウザの「戻る」ボタンなどに対応
|
| 85 |
+
window.addEventListener('popstate', function() {
|
| 86 |
+
const urlParams = new URLSearchParams(window.location.search);
|
| 87 |
+
const setName = urlParams.get('set') || 'A';
|
| 88 |
+
const index = parseInt(urlParams.get('index')) || 0;
|
| 89 |
+
updateFlashcard(setName, index);
|
| 90 |
});
|
| 91 |
</script>
|
| 92 |
</body>
|