Просмотр исходного кода

Fix HTML document structure in log.html

SybexXx 11 часов назад
Родитель
Сommit
afd0ad5cb7
1 измененных файлов с 61 добавлено и 1 удалено
  1. 61 1
      sd-card/html/log.html

+ 61 - 1
sd-card/html/log.html

@@ -55,7 +55,67 @@
                 <button class="button" onClick="window.location.href = getDomainname() + '/fileserver/log/message/'">Show Older Log Files</button>
             </div>
           </div>
-    </body>
+    
+
+    <script>  
+            function reload() {
+              //  document.getElementById('log').innerHTML += "<br><b>Reloading...<b><br><br>";
+                document.getElementById('log').innerHTML += "<b>Reloading...</b>";
+                window.scrollBy(0,document.body.scrollHeight);
+                funcRequest(getDomainname() + '/log');
+            } 
+    
+    
+            function processLogLine(line, index, arr) {
+                /* Make sure the whitespaces in the uptime field get persevered */
+                uptimePart = line.slice(0, line.indexOf("]")).replace(/ /g, "&nbsp;");
+                line = uptimePart + line.slice(line.indexOf("]"))
+    
+                if (line.includes("&lt;WRN&gt;")) {
+                    arr[index] = "<span style=\"color:#e83c00\">" + line + "</span>";
+                }
+                else if (line.includes("&lt;ERR&gt;")) {
+                    arr[index] = "<span style=\"color:red\"><b>" + line + "</b></span>";
+                }
+                else if (line.includes("&lt;DBG&gt;")) {
+                    arr[index] = "<span style=\"color:gray\">" + line + "</span>";
+                }
+                else {
+                    arr[index] = line;
+                }
+    
+                arr[index] += "<br>";
+            }
+    
+            async function funcRequest(url){
+                await fetch(url)
+                .then((res) => {
+                    if (!res.ok) {
+                        document.getElementById("log").innerHTML = "HTTP error " + res.status;
+                    }
+    
+                    return res.text();
+                })
+                .then((log) => {
+                    log = log.replace(/</g, "&lt;");
+                    log = log.replace(/>/g, "&gt;");
+                    logArr = log.split("\n");
+                    logArr.forEach(processLogLine);
+    
+                    document.getElementById('log').innerHTML = "<br>" + logArr.join("\n") + "&nbsp;";
+    
+                    window.scrollBy(0,document.body.scrollHeight);
+    
+                })
+                .catch((err) => {
+                    document.getElementById("log").innerHTML = err;
+                });
+            }
+    
+            funcRequest(getDomainname() + '/log');
+    
+        </script>
+</body>
 
     <script>  
         function reload() {