From 280898be6fc66f5c47270f2f2b21c0e9e1dc6793 Mon Sep 17 00:00:00 2001 From: Pablo Zmdl Date: Mon, 23 Feb 2026 13:36:28 +0100 Subject: [PATCH] Reload every 5s, but only if visible Signed-off-by: Pablo Zmdl --- php/templates/log.twig | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/php/templates/log.twig b/php/templates/log.twig index c14c9e9f..e5b91a31 100644 --- a/php/templates/log.twig +++ b/php/templates/log.twig @@ -13,7 +13,13 @@ // Give the browser a short moment to render all text and calculate the scrollHeight, to avoid // problems with scrolling to the bottom. setTimeout(() => window.scrollTo(0, document.body.scrollHeight), 100); - const reloadTimer = setTimeout(() => location.reload(), 10000); + // Reload after a short while if the window is visible to the user. + const reloadTimer = setTimeout(() => { + if (document.visibilityState === 'visible') { + location.reload() + } + }, 5000); + // Provide a button that allows to disable the reloads. const button = document.querySelector('button'); document.querySelector('button').addEventListener('click', (event) => { event.preventDefault(); @@ -21,6 +27,13 @@ button.disabled = true; button.textContent = 'Reloading was disabled'; }); + // Reload immediately if the window gets visible to the user again (unless the + // no-reload-button had been clicked). + document.addEventListener('visibilitychange', () => { + if (document.visibilityState === 'visible' && button.disabled !== true) { + location.reload(); + } + }); });