app/static/script.js aktualisiert
This commit is contained in:
parent
966b888070
commit
66cf1ce66b
@ -8,25 +8,17 @@ let stats = { correct: 0, total: 0 };
|
|||||||
|
|
||||||
function selectMainMode(mode) {
|
function selectMainMode(mode) {
|
||||||
mainMode = mode;
|
mainMode = mode;
|
||||||
subMode = null; // Reset submode
|
subMode = null;
|
||||||
|
|
||||||
// UI Updates
|
|
||||||
document.querySelectorAll('.mode-btn').forEach(b => b.classList.remove('active'));
|
document.querySelectorAll('.mode-btn').forEach(b => b.classList.remove('active'));
|
||||||
document.getElementById(`btn-main-${mode}`).classList.add('active');
|
document.getElementById(`btn-main-${mode}`).classList.add('active');
|
||||||
|
|
||||||
// Hide all submodes first
|
|
||||||
document.querySelectorAll('.submode-container').forEach(el => el.style.display = 'none');
|
document.querySelectorAll('.submode-container').forEach(el => el.style.display = 'none');
|
||||||
|
|
||||||
// Show correct submode
|
|
||||||
document.getElementById(`submode-${mode}`).style.display = 'block';
|
document.getElementById(`submode-${mode}`).style.display = 'block';
|
||||||
|
|
||||||
// Hide Start & Pages until submode selected
|
|
||||||
document.getElementById('page-section').style.display = 'none';
|
document.getElementById('page-section').style.display = 'none';
|
||||||
|
|
||||||
// Reset Submode buttons
|
|
||||||
document.querySelectorAll('.sub-btn').forEach(b => b.classList.remove('active'));
|
document.querySelectorAll('.sub-btn').forEach(b => b.classList.remove('active'));
|
||||||
|
|
||||||
// Fetch pages for this mode immediately
|
|
||||||
fetchPages(mode);
|
fetchPages(mode);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -36,7 +28,6 @@ function selectSubMode(mode) {
|
|||||||
document.querySelectorAll('.sub-btn').forEach(b => b.classList.remove('active'));
|
document.querySelectorAll('.sub-btn').forEach(b => b.classList.remove('active'));
|
||||||
document.getElementById(`btn-sub-${mode}`).classList.add('active');
|
document.getElementById(`btn-sub-${mode}`).classList.add('active');
|
||||||
|
|
||||||
// Now show page selection and start button
|
|
||||||
document.getElementById('page-section').style.display = 'block';
|
document.getElementById('page-section').style.display = 'block';
|
||||||
document.getElementById('btn-start').disabled = false;
|
document.getElementById('btn-start').disabled = false;
|
||||||
document.getElementById('btn-start').style.opacity = '1';
|
document.getElementById('btn-start').style.opacity = '1';
|
||||||
@ -49,7 +40,7 @@ function fetchPages(type) {
|
|||||||
const list = document.getElementById('page-list');
|
const list = document.getElementById('page-list');
|
||||||
list.innerHTML = '';
|
list.innerHTML = '';
|
||||||
|
|
||||||
// Auto-select logic: Select all by default
|
// Standard: Alle auswählen
|
||||||
selectedPages = pages;
|
selectedPages = pages;
|
||||||
updatePageDisplay();
|
updatePageDisplay();
|
||||||
|
|
||||||
@ -65,6 +56,15 @@ function fetchPages(type) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// --- NEU: FUNKTION FÜR "ALLE AN / ALLE AUS" ---
|
||||||
|
function toggleAllPages(state) {
|
||||||
|
const checkboxes = document.querySelectorAll('#page-list input');
|
||||||
|
checkboxes.forEach(cb => {
|
||||||
|
cb.checked = state;
|
||||||
|
});
|
||||||
|
updatePageSelection();
|
||||||
|
}
|
||||||
|
|
||||||
function updatePageSelection() {
|
function updatePageSelection() {
|
||||||
const checkboxes = document.querySelectorAll('#page-list input:checked');
|
const checkboxes = document.querySelectorAll('#page-list input:checked');
|
||||||
selectedPages = Array.from(checkboxes).map(cb => parseInt(cb.value));
|
selectedPages = Array.from(checkboxes).map(cb => parseInt(cb.value));
|
||||||
@ -75,9 +75,11 @@ function updatePageDisplay() {
|
|||||||
const d = document.getElementById('selected-pages-display');
|
const d = document.getElementById('selected-pages-display');
|
||||||
if (selectedPages.length === 0) {
|
if (selectedPages.length === 0) {
|
||||||
d.innerText = "Keine Seiten gewählt!";
|
d.innerText = "Keine Seiten gewählt!";
|
||||||
|
d.style.color = "red";
|
||||||
document.getElementById('btn-start').disabled = true;
|
document.getElementById('btn-start').disabled = true;
|
||||||
} else {
|
} else {
|
||||||
d.innerText = `Seiten: ${selectedPages.join(', ')}`;
|
d.innerText = `Seiten: ${selectedPages.join(', ')}`;
|
||||||
|
d.style.color = "#555";
|
||||||
if (subMode) document.getElementById('btn-start').disabled = false;
|
if (subMode) document.getElementById('btn-start').disabled = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -89,22 +91,22 @@ function startQuiz() {
|
|||||||
updateStats();
|
updateStats();
|
||||||
document.getElementById('setup-screen').style.display = 'none';
|
document.getElementById('setup-screen').style.display = 'none';
|
||||||
document.getElementById('quiz-screen').style.display = 'flex';
|
document.getElementById('quiz-screen').style.display = 'flex';
|
||||||
|
document.querySelector('.container').style.justifyContent = 'flex-start'; // Nach oben schieben
|
||||||
nextQuestion();
|
nextQuestion();
|
||||||
}
|
}
|
||||||
|
|
||||||
function stopQuiz() {
|
function stopQuiz() {
|
||||||
document.getElementById('quiz-screen').style.display = 'none';
|
document.getElementById('quiz-screen').style.display = 'none';
|
||||||
document.getElementById('setup-screen').style.display = 'block';
|
document.getElementById('setup-screen').style.display = 'block';
|
||||||
|
document.querySelector('.container').style.justifyContent = 'center'; // Wieder mittig
|
||||||
}
|
}
|
||||||
|
|
||||||
function nextQuestion() {
|
function nextQuestion() {
|
||||||
// UI Reset
|
|
||||||
document.getElementById('btn-check').style.display = 'block';
|
document.getElementById('btn-check').style.display = 'block';
|
||||||
document.getElementById('btn-next').style.display = 'none';
|
document.getElementById('btn-next').style.display = 'none';
|
||||||
document.getElementById('feedback').innerText = '';
|
document.getElementById('feedback').innerText = '';
|
||||||
document.getElementById('feedback').className = 'feedback';
|
document.getElementById('feedback').className = 'feedback';
|
||||||
|
|
||||||
// Clear Inputs
|
|
||||||
document.querySelectorAll('input').forEach(i => i.value = '');
|
document.querySelectorAll('input').forEach(i => i.value = '');
|
||||||
|
|
||||||
fetch('/api/question', {
|
fetch('/api/question', {
|
||||||
@ -145,16 +147,16 @@ function renderCard(card) {
|
|||||||
|
|
||||||
inpStd.style.display = 'none';
|
inpStd.style.display = 'none';
|
||||||
boxVerbs.style.display = 'flex';
|
boxVerbs.style.display = 'flex';
|
||||||
inpInf.style.display = 'none'; // Infinitiv ist gegeben
|
inpInf.style.display = 'none';
|
||||||
document.getElementById('inp-simple').focus();
|
document.getElementById('inp-simple').focus();
|
||||||
}
|
}
|
||||||
else if (card.type === 'irregular_full') {
|
else if (card.type === 'irregular_full') {
|
||||||
lbl.innerText = 'Unregelmäßiges Verb (Alle Formen):';
|
lbl.innerText = 'Unregelmäßiges Verb (Alle Formen):';
|
||||||
txt.innerText = card.question; // Deutsch
|
txt.innerText = card.question;
|
||||||
|
|
||||||
inpStd.style.display = 'none';
|
inpStd.style.display = 'none';
|
||||||
boxVerbs.style.display = 'flex';
|
boxVerbs.style.display = 'flex';
|
||||||
inpInf.style.display = 'block'; // Muss eingegeben werden
|
inpInf.style.display = 'block';
|
||||||
inpInf.focus();
|
inpInf.focus();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -166,7 +168,6 @@ function checkAnswer() {
|
|||||||
payload.input = document.getElementById('inp-standard').value;
|
payload.input = document.getElementById('inp-standard').value;
|
||||||
payload.correct = currentCard.answer;
|
payload.correct = currentCard.answer;
|
||||||
} else {
|
} else {
|
||||||
// Verben
|
|
||||||
payload.simple = document.getElementById('inp-simple').value;
|
payload.simple = document.getElementById('inp-simple').value;
|
||||||
payload.participle = document.getElementById('inp-part').value;
|
payload.participle = document.getElementById('inp-part').value;
|
||||||
payload.correct_simple = currentCard.answer_simple;
|
payload.correct_simple = currentCard.answer_simple;
|
||||||
@ -194,7 +195,6 @@ function checkAnswer() {
|
|||||||
finishTurn();
|
finishTurn();
|
||||||
} else if (res.status === 'typo') {
|
} else if (res.status === 'typo') {
|
||||||
fb.classList.add('typo');
|
fb.classList.add('typo');
|
||||||
// Darf nochmal probieren
|
|
||||||
} else {
|
} else {
|
||||||
fb.classList.add('wrong');
|
fb.classList.add('wrong');
|
||||||
finishTurn();
|
finishTurn();
|
||||||
@ -217,7 +217,6 @@ 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 Handler
|
|
||||||
document.addEventListener('keypress', (e) => {
|
document.addEventListener('keypress', (e) => {
|
||||||
if (e.key === 'Enter') {
|
if (e.key === 'Enter') {
|
||||||
const nextBtn = document.getElementById('btn-next');
|
const nextBtn = document.getElementById('btn-next');
|
||||||
@ -226,6 +225,5 @@ document.addEventListener('keypress', (e) => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Overlay Logic
|
|
||||||
function openPageOverlay() { document.getElementById('overlay').style.display = 'flex'; }
|
function openPageOverlay() { document.getElementById('overlay').style.display = 'flex'; }
|
||||||
function closeOverlay() { document.getElementById('overlay').style.display = 'none'; }
|
function closeOverlay() { document.getElementById('overlay').style.display = 'none'; }
|
||||||
Loading…
x
Reference in New Issue
Block a user