asdsad
All checks were successful
Deploy / deploy-staging (push) Successful in 6s
Deploy / deploy-production (push) Has been skipped

This commit is contained in:
2026-04-27 01:38:54 +02:00
parent bff852291e
commit 44945a31da
6 changed files with 83 additions and 13 deletions

View File

@@ -2,6 +2,13 @@
const page = document.querySelector('[data-pihole-page]');
if (!page) return;
const pageType = page.dataset.piholePage || 'dashboard';
const configuredRefreshSeconds = Number(page.dataset.refreshSeconds || 0);
const defaultRefreshSeconds = pageType === 'dashboard' ? 1 : 5;
const refreshSeconds = Number.isFinite(configuredRefreshSeconds) && configuredRefreshSeconds >= 0
? configuredRefreshSeconds
: defaultRefreshSeconds;
const fmt = new Intl.NumberFormat('de-DE');
const fmtDate = (ts) => {
if (!ts) return '';
@@ -11,7 +18,6 @@
let refreshTimer = null;
let loadInFlight = false;
let loadErrorShown = false;
const apiCall = async (action, payload = {}) => {
const res = await fetch(`/module/pihole/api?action=${encodeURIComponent(action)}`,
@@ -265,7 +271,6 @@
renderList(document.querySelector('[data-top-queries]'), data.aggregate?.top_queries, 'Keine Daten');
renderList(document.querySelector('[data-top-clients]'), data.aggregate?.query_sources, 'Keine Daten');
renderBlocked(document.querySelector('[data-recent-blocked]'), data.aggregate?.recent_blocked);
loadErrorShown = false;
const existing = page.querySelector('[data-pihole-load-error]');
if (existing) existing.remove();
} catch (err) {
@@ -278,19 +283,37 @@
page.appendChild(message);
}
message.textContent = `Fehler beim Laden der Pi-hole Daten: ${err.message}`;
loadErrorShown = true;
} finally {
loadInFlight = false;
}
};
const stopAutoRefresh = () => {
if (refreshTimer !== null) {
window.clearInterval(refreshTimer);
refreshTimer = null;
}
};
const startAutoRefresh = () => {
stopAutoRefresh();
if (refreshSeconds <= 0 || document.visibilityState !== 'visible') {
return;
}
refreshTimer = window.setInterval(loadDashboard, refreshSeconds * 1000);
};
bindActionButtons();
bindForms();
loadDashboard();
refreshTimer = window.setInterval(loadDashboard, 1000);
window.addEventListener('beforeunload', () => {
if (refreshTimer !== null) {
window.clearInterval(refreshTimer);
startAutoRefresh();
document.addEventListener('visibilitychange', () => {
if (document.visibilityState === 'visible') {
loadDashboard();
startAutoRefresh();
return;
}
stopAutoRefresh();
});
window.addEventListener('beforeunload', stopAutoRefresh);
})();