autoscroll sidebar log

master
Kevin Froman 2020-10-17 10:11:07 +00:00
parent 60c7e6cb37
commit 8f52fa4669
3 changed files with 25 additions and 2 deletions

View File

@ -7,3 +7,8 @@
padding-top: 5px;
font-size: 1em;
}
#logfileOutput{
max-height: 700px;
overflow-y: scroll;
}

View File

@ -20,8 +20,8 @@
Add Peer
</a>
</div>
<pre id="logfileOutput"></pre>
</div>
<pre id="logfileOutput"></pre>
</div>
</div>
</div>

View File

@ -10,7 +10,12 @@ fetch('/shared/sidebar/sidebar.html', {
sidebarAddPeerRegister()
})
var sidebarActive = false
var lastLogOffset = 0
var logActive = false
async function showLog(){
fetch('/readfileoffset/onionr.log?offset=' + lastLogOffset, {
method: 'GET',
@ -20,8 +25,12 @@ async function showLog(){
.then((resp) => resp.json())
.then(function(resp){
lastLogOffset = resp['new_offset']
document.getElementById('logfileOutput').innerText += resp.data.replace(
var logfileOutputEl = document.getElementById('logfileOutput')
logfileOutputEl.innerText += resp.data.replace(
/[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]/g, '')
if (!logActive){
logfileOutputEl.scrollTop = logfileOutputEl.scrollHeight;
}
})
}
@ -72,11 +81,20 @@ function sidebarAddPeerRegister(){
window.addEventListener("keydown", function(event) {
var refreshSideBarInterval = null
document.getElementById('logfileOutput').onmouseenter = function(e){
logActive = true
}
document.getElementById('logfileOutput').onmouseleave = function(e){
logActive = false
}
document.getElementsByClassName('closeSidebar')[0].onclick = function(){
sidebarActive = false
clearInterval(sidebarLogInterval)
clearInterval(refreshSideBarInterval)
}
if (event.key === "s"){
sidebarActive = true
if (document.activeElement.nodeName == "TEXTAREA" || document.activeElement.nodeName == "INPUT"){
if (! document.activeElement.hasAttribute("readonly")){
return