app/static/script.js aktualisiert
This commit is contained in:
parent
8f1aa4e77f
commit
404e81ad29
@ -36,7 +36,7 @@ function fetchPages(type) {
|
|||||||
const list = document.getElementById('page-list');
|
const list = document.getElementById('page-list');
|
||||||
list.innerHTML = '';
|
list.innerHTML = '';
|
||||||
|
|
||||||
selectedPages = []; // Standard: Nichts ausgewählt
|
selectedPages = [];
|
||||||
updatePageDisplay();
|
updatePageDisplay();
|
||||||
|
|
||||||
pages.forEach(p => {
|
pages.forEach(p => {
|
||||||
@ -96,16 +96,15 @@ function nextQuestion() {
|
|||||||
const btn = document.getElementById('btn-action');
|
const btn = document.getElementById('btn-action');
|
||||||
const fb = document.getElementById('feedback');
|
const fb = document.getElementById('feedback');
|
||||||
|
|
||||||
// Button zurücksetzen auf "Prüfen"
|
|
||||||
btn.innerText = "Prüfen";
|
btn.innerText = "Prüfen";
|
||||||
btn.onclick = checkAnswer;
|
btn.onclick = checkAnswer;
|
||||||
btn.className = "action-btn primary"; // Farbe Grün
|
btn.className = "action-btn primary";
|
||||||
|
|
||||||
fb.innerText = '';
|
fb.innerText = '';
|
||||||
fb.className = 'feedback';
|
fb.className = 'feedback';
|
||||||
|
|
||||||
document.querySelectorAll('input').forEach(i => i.value = '');
|
document.querySelectorAll('input').forEach(i => i.value = '');
|
||||||
attempts = 0; // Versuche resetten
|
attempts = 0;
|
||||||
|
|
||||||
fetch('/api/question', {
|
fetch('/api/question', {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
@ -182,31 +181,54 @@ function checkAnswer() {
|
|||||||
.then(res => res.json())
|
.then(res => res.json())
|
||||||
.then(res => {
|
.then(res => {
|
||||||
const fb = document.getElementById('feedback');
|
const fb = document.getElementById('feedback');
|
||||||
fb.innerText = res.msg;
|
|
||||||
|
|
||||||
if (res.status === 'correct') {
|
if (res.status === 'correct') {
|
||||||
// RICHTIG -> Button auf "Weiter" schalten
|
// Richtig -> Sofort grün und weiter
|
||||||
|
fb.innerText = res.msg;
|
||||||
fb.className = 'feedback correct';
|
fb.className = 'feedback correct';
|
||||||
stats.correct++;
|
stats.correct++;
|
||||||
switchToNextMode();
|
switchToNextMode();
|
||||||
|
|
||||||
} else if (res.status === 'typo') {
|
} else if (res.status === 'typo') {
|
||||||
|
// Tippfehler -> Warnung, zählt als Versuch
|
||||||
|
fb.innerText = res.msg;
|
||||||
fb.className = 'feedback typo';
|
fb.className = 'feedback typo';
|
||||||
attempts++;
|
attempts++;
|
||||||
checkAttempts(res.msg); // Typo zählt auch als Versuch
|
checkAttempts();
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
// FALSCH
|
// Falsch
|
||||||
fb.className = 'feedback wrong';
|
|
||||||
attempts++;
|
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) {
|
if (attempts >= 3) {
|
||||||
// Zu viele Versuche -> Button auf "Weiter"
|
const fb = document.getElementById('feedback');
|
||||||
document.getElementById('feedback').innerText = "Leider falsch (3 Versuche). " + msg;
|
let solution = "";
|
||||||
stats.total++; // Zählt als fertig (aber falsch)
|
|
||||||
|
// 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();
|
updateStats();
|
||||||
switchToNextMode();
|
switchToNextMode();
|
||||||
}
|
}
|
||||||
@ -215,14 +237,19 @@ function checkAttempts(msg) {
|
|||||||
function switchToNextMode() {
|
function switchToNextMode() {
|
||||||
const btn = document.getElementById('btn-action');
|
const btn = document.getElementById('btn-action');
|
||||||
btn.innerText = "Weiter";
|
btn.innerText = "Weiter";
|
||||||
btn.onclick = finishTurn; // Beim Klick auf Weiter -> finishTurn
|
btn.onclick = finishTurn;
|
||||||
btn.focus();
|
btn.focus();
|
||||||
}
|
}
|
||||||
|
|
||||||
function finishTurn() {
|
function finishTurn() {
|
||||||
// Wenn "Weiter" geklickt wird
|
// Wenn "Weiter" geklickt wird
|
||||||
if (document.getElementById('btn-action').innerText === "Weiter") {
|
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();
|
updateStats();
|
||||||
nextQuestion();
|
nextQuestion();
|
||||||
}
|
}
|
||||||
@ -235,12 +262,8 @@ function updateStats() {
|
|||||||
document.getElementById('stats-text').innerText = `${p}% Richtig (${stats.correct}/${stats.total})`;
|
document.getElementById('stats-text').innerText = `${p}% Richtig (${stats.correct}/${stats.total})`;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Enter Key: Klickt einfach den aktiven Button
|
|
||||||
document.addEventListener('keypress', (e) => {
|
document.addEventListener('keypress', (e) => {
|
||||||
if (e.key === 'Enter') {
|
if (e.key === 'Enter') {
|
||||||
document.getElementById('btn-action').click();
|
document.getElementById('btn-action').click();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
function openPageOverlay() { document.getElementById('overlay').style.display = 'flex'; }
|
|
||||||
function closeOverlay() { document.getElementById('overlay').style.display = 'none'; }
|
|
||||||
Loading…
x
Reference in New Issue
Block a user