app/static/script.js aktualisiert

This commit is contained in:
sascha 2026-01-28 18:51:25 +00:00
parent 8f1aa4e77f
commit 404e81ad29

View File

@ -36,7 +36,7 @@ function fetchPages(type) {
const list = document.getElementById('page-list');
list.innerHTML = '';
selectedPages = []; // Standard: Nichts ausgewählt
selectedPages = [];
updatePageDisplay();
pages.forEach(p => {
@ -96,16 +96,15 @@ function nextQuestion() {
const btn = document.getElementById('btn-action');
const fb = document.getElementById('feedback');
// Button zurücksetzen auf "Prüfen"
btn.innerText = "Prüfen";
btn.onclick = checkAnswer;
btn.className = "action-btn primary"; // Farbe Grün
btn.className = "action-btn primary";
fb.innerText = '';
fb.className = 'feedback';
document.querySelectorAll('input').forEach(i => i.value = '');
attempts = 0; // Versuche resetten
attempts = 0;
fetch('/api/question', {
method: 'POST',
@ -182,31 +181,54 @@ function checkAnswer() {
.then(res => res.json())
.then(res => {
const fb = document.getElementById('feedback');
fb.innerText = res.msg;
if (res.status === 'correct') {
// RICHTIG -> Button auf "Weiter" schalten
// Richtig -> Sofort grün und weiter
fb.innerText = res.msg;
fb.className = 'feedback correct';
stats.correct++;
switchToNextMode();
} else if (res.status === 'typo') {
// Tippfehler -> Warnung, zählt als Versuch
fb.innerText = res.msg;
fb.className = 'feedback typo';
attempts++;
checkAttempts(res.msg); // Typo zählt auch als Versuch
checkAttempts();
} else {
// FALSCH
fb.className = 'feedback wrong';
// Falsch
attempts++;
checkAttempts(res.msg);
if (attempts < 3) {
fb.innerText = `Falsch. Versuch ${attempts}/3. Probiere es noch einmal!`;
fb.className = 'feedback wrong';
// Button bleibt auf "Prüfen", man kann es nochmal versuchen
} else {
checkAttempts(); // Lösen
}
}
});
}
function checkAttempts(msg) {
function checkAttempts() {
// Wenn 3 mal falsch (oder aufgegeben wird)
if (attempts >= 3) {
// Zu viele Versuche -> Button auf "Weiter"
document.getElementById('feedback').innerText = "Leider falsch (3 Versuche). " + msg;
stats.total++; // Zählt als fertig (aber falsch)
const fb = document.getElementById('feedback');
let solution = "";
// Lösungstext zusammenbauen
if (currentCard.type === 'vocab') {
solution = currentCard.answer;
} else if (currentCard.type === 'irregular_standard') {
solution = `${currentCard.answer_simple} -> ${currentCard.answer_participle}`;
} else {
solution = `${currentCard.answer_infinitive} -> ${currentCard.answer_simple} -> ${currentCard.answer_participle}`;
}
fb.innerText = `Leider nicht geschafft. Lösung: ${solution}`;
fb.className = 'feedback wrong';
stats.total++;
updateStats();
switchToNextMode();
}
@ -215,14 +237,19 @@ function checkAttempts(msg) {
function switchToNextMode() {
const btn = document.getElementById('btn-action');
btn.innerText = "Weiter";
btn.onclick = finishTurn; // Beim Klick auf Weiter -> finishTurn
btn.onclick = finishTurn;
btn.focus();
}
function finishTurn() {
// Wenn "Weiter" geklickt wird
if (document.getElementById('btn-action').innerText === "Weiter") {
if(attempts < 3) stats.total++; // Wenn richtig, hier Zähler hoch
// Nur wenn es beim ersten Mal oder nach Typo geklappt hat, zählt es als "correct" für die Statistik
// Die Logik oben (bei status correct) hat stats.correct++ schon gemacht.
// Hier zählen wir nur total hoch, wenn es noch nicht passiert ist (bei failure passierte es schon)
if (attempts < 3 && document.getElementById('feedback').classList.contains('correct')) {
stats.total++;
}
updateStats();
nextQuestion();
}
@ -235,12 +262,8 @@ function updateStats() {
document.getElementById('stats-text').innerText = `${p}% Richtig (${stats.correct}/${stats.total})`;
}
// Enter Key: Klickt einfach den aktiven Button
document.addEventListener('keypress', (e) => {
if (e.key === 'Enter') {
document.getElementById('btn-action').click();
}
});
function openPageOverlay() { document.getElementById('overlay').style.display = 'flex'; }
function closeOverlay() { document.getElementById('overlay').style.display = 'none'; }
});