A live bird collage card for your Home Assistant dashboard.
Update overview.php
ehpersonal382027967b7bab
diff --git a/scripts/overview.php b/scripts/overview.phpindex 2af64f81..b844c0e2 100644--- a/scripts/overview.php+++ b/scripts/overview.php@@ -111,20 +111,9 @@ if(isset($_GET['ajax_detections']) && $_GET['ajax_detections'] == "true" && isse}die();}++if(isset($_GET['ajax_left_chart']) && $_GET['ajax_left_chart'] == "true") {?>-<head>- <meta charset="UTF-8">- <meta name="viewport" content="width=device-width, initial-scale=1">- <title>Overview</title>-<style>-body::-webkit-scrollbar {- display:none-}-</style>-</head>-<div class="overview">-<div class="overview-stats">-<div class="left-column"><table><tr><th>Total</th>@@ -153,6 +142,24 @@ body::-webkit-scrollbar {</form></tr></table>+<?php+die();+}+?>+<head>+ <meta charset="UTF-8">+ <meta name="viewport" content="width=device-width, initial-scale=1">+ <title>Overview</title>+<style>+body::-webkit-scrollbar {+ display:none+}+</style>+</head>+<div class="overview">+<div class="overview-stats">+<div class="left-column">+</table></div><div class="right-column"><div class="chart">@@ -170,12 +177,6 @@ if (file_exists('./Charts/'.$chart)) {echo "<p>No Detections For Today</p>";}?>-<script>-// every $refresh seconds, this loop will run and refresh the spectrogram image-window.setInterval(function(){- document.getElementById("chart").src = "/Charts/<?php echo $chart;?>?nocache="+Date.now();-}, <?php echo $refresh; ?>*1000);-</script></div><div id="most_recent_detection"></div>@@ -186,12 +187,6 @@ $refresh = $config['RECORDING_LENGTH'];$time = time();echo "<img id=\"spectrogramimage\" src=\"/spectrogram.png?nocache=$time\">";?>-<script>-// every $refresh seconds, this loop will run and refresh the spectrogram image-window.setInterval(function(){- document.getElementById("spectrogramimage").src = "/spectrogram.png?nocache="+Date.now();-}, <?php echo $refresh; ?>*1000);-</script></div></div>@@ -204,11 +199,22 @@ function loadDetectionIfNewExists(previous_detection_identifier=undefined) {// if there's a new detection that needs to be updated to the pageif(this.responseText.length > 0) {document.getElementById("most_recent_detection").innerHTML = this.responseText;++ // only going to load left chart if there's a new detection+ loadLeftChart();}}xhttp.open("GET", "overview.php?ajax_detections=true&previous_detection_identifier="+previous_detection_identifier, true);xhttp.send();}+function loadLeftChart() {+ const xhttp = new XMLHttpRequest();+ xhttp.onload = function() {+ document.getElementsByClassName("left-column")[0].innerHTML = this.responseText;+ }+ xhttp.open("GET", "overview.php?ajax_left_chart=true", true);+ xhttp.send();+}window.setInterval(function(){var videoelement = document.getElementsByTagName("video")[0];if(typeof videoelement !== "undefined") {@@ -220,9 +226,15 @@ window.setInterval(function(){// image or audio didn't load for some reason, force a refresh in 5 secondsloadDetectionIfNewExists();}-}, 5*1000);+}, <?php echo intval($refresh/4); ?>*1000);window.addEventListener("load", function(){loadDetectionIfNewExists();+ loadLeftChart();});+// every $refresh seconds, this loop will run and refresh the spectrogram image+window.setInterval(function(){+ document.getElementById("chart").src = "/Charts/<?php echo $chart;?>?nocache="+Date.now();+ document.getElementById("spectrogramimage").src = "/spectrogram.png?nocache="+Date.now();+}, <?php echo $refresh; ?>*1000);</script>