1
0
mirror of https://github.com/taigrr/log-socket synced 2025-01-18 04:53:14 -08:00

Adds autoscroll feature to browser

This commit is contained in:
2021-04-09 10:39:23 -07:00
parent b744f083dc
commit 2c7cf0494e
2 changed files with 16 additions and 3 deletions

View File

@@ -3,10 +3,13 @@ package browser
import (
"html/template"
"net/http"
"strings"
)
func LogSocketViewHandler(w http.ResponseWriter, r *http.Request) {
homeTemplate.Execute(w, "ws://"+r.Host+r.URL.Path+"/ws")
wsResource := "ws://" + r.Host + r.URL.Path
wsResource = strings.TrimSuffix(wsResource, "/") + "/ws"
homeTemplate.Execute(w, wsResource)
}
var homeTemplate = template.Must(template.New("").Parse(`
@@ -18,6 +21,7 @@ var homeTemplate = template.Must(template.New("").Parse(`
<body>
<center>
<input type="text" id="search" onkeyup="filterTable()" placeholder="Filter...">
<input type="checkbox" id="shouldScroll" checked>Enable Autoscroll<br>
<table id="logHeaders" style="text-align:left; width:80%;" >
<tbody>
<tr class="header">
@@ -183,6 +187,14 @@ function filterTable() {
}
}
function pageScroll() {
if (document.getElementById('shouldScroll').checked) {
document.getElementById('tableWrapper').scrollBy(0,10);
}
setTimeout(pageScroll,10);
}
document.getElementById("delete").addEventListener("click", function(){
clearTable()
@@ -192,6 +204,7 @@ document.getElementById("download").addEventListener("click", function(){
download(application+'.json',JSON.stringify(logs));
}, false);
openSocket();
pageScroll();
</script>
</footer>