De commit introduceert een debug tijdsynchronisatie tussen de cron script, de hoofdpagina en de Flask API. Deze functies maken het mogelijk om de huidige tijd te simuleren met een instelbare offset voor testdoeleinden. Het volume en de gebedstijden passen zich nu aan op basis van deze debug tijd indien actief. Debugger gebruikers kunnen via de nieuwe '/api/debug-time' endpoint de tijd aanpassen. De wijzigingen verbeteren de testbaarheid van de applicatie en zorgen ervoor dat gebedsafroepen en volumebepaling correct functioneren onder simulatieomstandigheden.
304 lines
10 KiB
JavaScript
304 lines
10 KiB
JavaScript
function updateCurrentTime() {
|
|
// Check eerst of debug mode actief is
|
|
fetch('/api/debug-time')
|
|
.then(response => response.json())
|
|
.then(data => {
|
|
if (data.success && data.debug_active) {
|
|
// Gebruik debug tijd
|
|
document.getElementById("current-time").textContent = data.current_time_display;
|
|
console.log(`🔧 Debug tijd actief: ${data.current_time_display} (offset: ${data.offset}s)`);
|
|
} else {
|
|
// Gebruik normale tijd
|
|
const now = new Date();
|
|
const timeStr = now.toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' });
|
|
document.getElementById("current-time").textContent = timeStr;
|
|
}
|
|
|
|
// Update datum informatie elke minuut
|
|
updateDateInfo();
|
|
})
|
|
.catch(error => {
|
|
// Fallback naar normale tijd bij fout
|
|
const now = new Date();
|
|
const timeStr = now.toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' });
|
|
document.getElementById("current-time").textContent = timeStr;
|
|
|
|
// Update datum informatie elke minuut
|
|
updateDateInfo();
|
|
});
|
|
}
|
|
|
|
function updateDateInfo() {
|
|
fetch('/api/date-info')
|
|
.then(response => response.json())
|
|
.then(data => {
|
|
const gregorianElement = document.querySelector('.gregorian-datum');
|
|
const hijriArabicElement = document.querySelector('.hijri-datum-arabic');
|
|
const hijriDutchElement = document.querySelector('.hijri-datum-dutch');
|
|
|
|
if (gregorianElement) gregorianElement.textContent = data.gregorian_full;
|
|
if (hijriArabicElement) hijriArabicElement.textContent = data.hijri_arabic;
|
|
if (hijriDutchElement) hijriDutchElement.textContent = data.hijri_dutch;
|
|
})
|
|
.catch(error => {
|
|
console.log('Fout bij bijwerken datum:', error);
|
|
});
|
|
}
|
|
|
|
// Gebedstijden ophalen uit een globale variabele (wordt in de template gezet)
|
|
let prayerTimes = window.prayerTimes || [];
|
|
let prayerNames = window.prayerNames || [];
|
|
let currentPrayerIndex = 0;
|
|
let isNextDayPrayer = false;
|
|
|
|
function startCountdowns(times, names) {
|
|
prayerTimes = times;
|
|
prayerNames = names;
|
|
|
|
getNextPrayer().then(nextPrayer => {
|
|
currentPrayerIndex = nextPrayer.index;
|
|
isNextDayPrayer = nextPrayer.isNextDay;
|
|
startCountdown(prayerTimes[currentPrayerIndex], prayerNames[currentPrayerIndex], isNextDayPrayer);
|
|
}).catch(error => {
|
|
console.log('Fout bij bepalen volgende gebed:', error);
|
|
// Fallback
|
|
currentPrayerIndex = 0;
|
|
isNextDayPrayer = false;
|
|
startCountdown(prayerTimes[currentPrayerIndex], prayerNames[currentPrayerIndex], isNextDayPrayer);
|
|
});
|
|
}
|
|
|
|
function getNextPrayer() {
|
|
// Gebruik debug tijd als actief
|
|
return fetch('/api/debug-time')
|
|
.then(response => response.json())
|
|
.then(data => {
|
|
let currentTime;
|
|
|
|
if (data.success && data.debug_active) {
|
|
// Gebruik debug tijd
|
|
const debugTime = data.current_time_display;
|
|
const [h, m] = debugTime.split(":");
|
|
currentTime = parseInt(h) * 60 + parseInt(m);
|
|
console.log(`🔧 Debug tijd gebruikt voor countdown: ${debugTime}`);
|
|
} else {
|
|
// Gebruik normale tijd
|
|
const now = new Date();
|
|
currentTime = now.getHours() * 60 + now.getMinutes();
|
|
}
|
|
|
|
// Zoek naar volgende gebed vandaag
|
|
for (let i = 0; i < prayerTimes.length; i++) {
|
|
const [h, m] = prayerTimes[i].split(":");
|
|
const prayerTimeMinutes = parseInt(h) * 60 + parseInt(m);
|
|
|
|
if (prayerTimeMinutes > currentTime) {
|
|
return { index: i, isNextDay: false };
|
|
}
|
|
}
|
|
|
|
// Alle gebeden van vandaag zijn voorbij, volgende is eerste gebed van morgen
|
|
return { index: 0, isNextDay: true };
|
|
})
|
|
.catch(error => {
|
|
console.log('Fout bij ophalen debug tijd, gebruik normale tijd:', error);
|
|
// Fallback naar normale tijd
|
|
const now = new Date();
|
|
const currentTime = now.getHours() * 60 + now.getMinutes();
|
|
|
|
for (let i = 0; i < prayerTimes.length; i++) {
|
|
const [h, m] = prayerTimes[i].split(":");
|
|
const prayerTimeMinutes = parseInt(h) * 60 + parseInt(m);
|
|
|
|
if (prayerTimeMinutes > currentTime) {
|
|
return { index: i, isNextDay: false };
|
|
}
|
|
}
|
|
|
|
return { index: 0, isNextDay: true };
|
|
});
|
|
}
|
|
|
|
function startCountdown(targetTimeStr, prayerName, isNextDay = false) {
|
|
const parts = targetTimeStr.split(":");
|
|
let target = new Date();
|
|
target.setHours(parseInt(parts[0]));
|
|
target.setMinutes(parseInt(parts[1]));
|
|
target.setSeconds(0);
|
|
|
|
// Als het volgende gebed morgen is, voeg een dag toe
|
|
if (isNextDay) {
|
|
target.setDate(target.getDate() + 1);
|
|
}
|
|
|
|
// Update de naam met "morgen" indicator als nodig
|
|
const displayName = isNextDay ? `${prayerName} (morgen)` : prayerName;
|
|
document.querySelector('.huidig-gebed-bottom .naam').textContent = displayName;
|
|
|
|
function update() {
|
|
// Gebruik debug tijd als actief
|
|
fetch('/api/debug-time')
|
|
.then(response => response.json())
|
|
.then(data => {
|
|
let now;
|
|
|
|
if (data.success && data.debug_active) {
|
|
// Gebruik debug tijd
|
|
const debugTime = data.current_time;
|
|
const [h, m, s] = debugTime.split(":");
|
|
now = new Date();
|
|
now.setHours(parseInt(h), parseInt(m), parseInt(s), 0);
|
|
} else {
|
|
// Gebruik normale tijd
|
|
now = new Date();
|
|
}
|
|
|
|
let diff = Math.floor((target - now) / 1000);
|
|
|
|
if (diff <= 0) {
|
|
// Speel adhaan af via browser
|
|
const audio = document.getElementById('adhanAudio');
|
|
if (audio) audio.play();
|
|
|
|
// Trigger Adzkaar scherm na 3 seconden (geef adhaan tijd om te starten)
|
|
setTimeout(() => {
|
|
triggerAdzkaarScreen(displayName);
|
|
}, 3000);
|
|
|
|
// Ga naar volgende gebed
|
|
if (isNextDayPrayer) {
|
|
// We waren aan het wachten op het eerste gebed van de nieuwe dag
|
|
// Nu gaan we naar het tweede gebed van vandaag (nieuwe dag)
|
|
currentPrayerIndex = 1;
|
|
isNextDayPrayer = false;
|
|
|
|
if (currentPrayerIndex < prayerTimes.length) {
|
|
startCountdown(prayerTimes[currentPrayerIndex], prayerNames[currentPrayerIndex], false);
|
|
} else {
|
|
// Dit zou niet moeten gebeuren, maar veiligheidshalve
|
|
currentPrayerIndex = 0;
|
|
isNextDayPrayer = true;
|
|
startCountdown(prayerTimes[currentPrayerIndex], prayerNames[currentPrayerIndex], true);
|
|
}
|
|
} else {
|
|
// Normaal doorgang naar volgende gebed
|
|
currentPrayerIndex++;
|
|
|
|
if (currentPrayerIndex >= prayerTimes.length) {
|
|
// Alle gebeden van vandaag zijn klaar, ga naar eerste gebed van morgen
|
|
currentPrayerIndex = 0;
|
|
isNextDayPrayer = true;
|
|
}
|
|
|
|
startCountdown(prayerTimes[currentPrayerIndex], prayerNames[currentPrayerIndex], isNextDayPrayer);
|
|
}
|
|
return;
|
|
}
|
|
|
|
// Toon countdown
|
|
const h = String(Math.floor(diff / 3600)).padStart(2, '0');
|
|
const m = String(Math.floor((diff % 3600) / 60)).padStart(2, '0');
|
|
const s = String(diff % 60).padStart(2, '0');
|
|
|
|
document.getElementById("countdown").textContent = `${h}:${m}:${s}`;
|
|
})
|
|
.catch(error => {
|
|
// Fallback naar normale tijd
|
|
const now = new Date();
|
|
let diff = Math.floor((target - now) / 1000);
|
|
|
|
if (diff <= 0) {
|
|
// Speel adhaan af via browser
|
|
const audio = document.getElementById('adhanAudio');
|
|
if (audio) audio.play();
|
|
|
|
// Trigger Adzkaar scherm na 3 seconden (geef adhaan tijd om te starten)
|
|
setTimeout(() => {
|
|
triggerAdzkaarScreen(displayName);
|
|
}, 3000);
|
|
|
|
// Ga naar volgende gebed
|
|
if (isNextDayPrayer) {
|
|
currentPrayerIndex = 1;
|
|
isNextDayPrayer = false;
|
|
|
|
if (currentPrayerIndex < prayerTimes.length) {
|
|
startCountdown(prayerTimes[currentPrayerIndex], prayerNames[currentPrayerIndex], false);
|
|
} else {
|
|
currentPrayerIndex = 0;
|
|
isNextDayPrayer = true;
|
|
startCountdown(prayerTimes[currentPrayerIndex], prayerNames[currentPrayerIndex], true);
|
|
}
|
|
} else {
|
|
currentPrayerIndex++;
|
|
|
|
if (currentPrayerIndex >= prayerTimes.length) {
|
|
currentPrayerIndex = 0;
|
|
isNextDayPrayer = true;
|
|
}
|
|
|
|
startCountdown(prayerTimes[currentPrayerIndex], prayerNames[currentPrayerIndex], isNextDayPrayer);
|
|
}
|
|
return;
|
|
}
|
|
|
|
// Toon countdown
|
|
const h = String(Math.floor(diff / 3600)).padStart(2, '0');
|
|
const m = String(Math.floor((diff % 3600) / 60)).padStart(2, '0');
|
|
const s = String(diff % 60).padStart(2, '0');
|
|
|
|
document.getElementById("countdown").textContent = `${h}:${m}:${s}`;
|
|
});
|
|
}
|
|
|
|
update();
|
|
window._countdownInterval && clearInterval(window._countdownInterval);
|
|
window._countdownInterval = setInterval(update, 1000);
|
|
}
|
|
|
|
function setupThemeToggle() {
|
|
const toggleBtn = document.getElementById("themeToggle");
|
|
const html = document.documentElement;
|
|
|
|
function applyTheme(theme) {
|
|
html.className = theme;
|
|
localStorage.setItem('theme', theme);
|
|
}
|
|
|
|
const saved = localStorage.getItem('theme') || 'light';
|
|
applyTheme(saved);
|
|
|
|
toggleBtn.addEventListener("click", () => {
|
|
const current = html.className === 'light' ? 'dark' : 'light';
|
|
applyTheme(current);
|
|
});
|
|
}
|
|
|
|
function triggerAdzkaarScreen(prayerName) {
|
|
// Check eerst of Adzkaar is ingeschakeld via API
|
|
fetch('/api/trigger-adzkaar', {
|
|
method: 'POST',
|
|
headers: { 'Content-Type': 'application/json' }
|
|
})
|
|
.then(response => response.json())
|
|
.then(data => {
|
|
if (data.success) {
|
|
console.log(`📿 Adzkaar scherm wordt getoond na ${prayerName}`);
|
|
|
|
// Toon Adzkaar modal in plaats van nieuwe pagina
|
|
if (window.showAdzkaarModal) {
|
|
// Gebruik de duur uit de API response of standaard 5 minuten
|
|
const durationMinutes = data.duration_minutes || 5;
|
|
window.showAdzkaarModal(durationMinutes);
|
|
} else {
|
|
console.log('📿 Adzkaar modal functie niet beschikbaar');
|
|
}
|
|
} else {
|
|
console.log(`📿 Adzkaar niet getoond: ${data.error}`);
|
|
}
|
|
})
|
|
.catch(error => {
|
|
console.log(`❌ Fout bij Adzkaar trigger: ${error.message}`);
|
|
});
|
|
}
|