change refresh interval behaviour

This commit is contained in:
Alex Janka 2024-01-07 11:21:33 +11:00
parent 77e9b19d26
commit 878652c24a

View file

@ -10,9 +10,20 @@
<script type="text/javascript"> <script type="text/javascript">
const api_url = window.location.protocol + "//" + window.location.hostname + ":" + window.location.port; const api_url = window.location.protocol + "//" + window.location.hostname + ":" + window.location.port;
function register() { refresh_interval = register();
refresh(); refresh();
setInterval(refresh, 15000); document.addEventListener("visibilitychange", () => {
if (document.hidden) {
clearInterval(refresh_interval);
} else {
refresh();
refresh_interval = register();
}
});
function register() {
return setInterval(refresh, 10000);
} }
function flash() { function flash() {
@ -66,7 +77,7 @@
</script> </script>
</head> </head>
<body onload="register()"></body> <body></body>
<button onclick="flash()">flash</button> <button onclick="flash()">flash</button>
<div id="info"></div> <div id="info"></div>