-
Notifications
You must be signed in to change notification settings - Fork 306
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
39 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,73 +1,75 @@ | ||
<html> | ||
<html lang="en"> | ||
<head> | ||
<title>Log Viewer for Kodi</title> | ||
<script type="text/javascript"> | ||
var offset = 0; | ||
var polling = null; | ||
let offset = 0; | ||
let polling = null; | ||
|
||
var param = function (key, fallback) { | ||
var query = window.location.search.substring(1); | ||
var parameters = query.split('&'); | ||
for (var i = 0; i < parameters.length; i++) { | ||
var pair = parameters[i].split('='); | ||
if (pair[0] == key) { | ||
return unescape(pair[1]); | ||
const param = function (key, fallback) { | ||
const query = window.location.search.substring(1); | ||
const parameters = query.split('&'); | ||
for (let i = 0; i < parameters.length; i++) { | ||
const pair = parameters[i].split('='); | ||
if (pair[0] === key) { | ||
return decodeURI(pair[1]); | ||
} | ||
} | ||
return fallback; | ||
} | ||
}; | ||
|
||
var append = function (text) { | ||
const append = function (text) { | ||
if (text) { | ||
var element = document.getElementById('tail'); | ||
var scrollDown = element.scrollHeight - element.scrollTop- element.clientHeight < 1; | ||
const element = document.getElementById('tail'); | ||
const scrollDown = element.scrollHeight - element.scrollTop - element.clientHeight < 1; | ||
element.textContent += text; | ||
if (scrollDown) { | ||
element.scrollTop = element.scrollHeight; | ||
// element.scrollLeft = 0; | ||
} | ||
} | ||
} | ||
}; | ||
|
||
var request = function (uri, callback) { | ||
var xhr = new XMLHttpRequest(); | ||
const request = function (uri, callback) { | ||
const xhr = new XMLHttpRequest(); | ||
xhr.open('GET', uri, true); | ||
xhr.onreadystatechange = function () { | ||
if (xhr.readyState == 4 && xhr.status == 200) { | ||
var newOffset = xhr.getResponseHeader('X-Seek-Offset'); | ||
if (newOffset) offset = parseInt(newOffset); | ||
if (xhr.readyState === 4 && xhr.status === 200) { | ||
const newOffset = xhr.getResponseHeader('X-Seek-Offset'); | ||
if (newOffset) { | ||
offset = parseInt(newOffset); | ||
} | ||
callback(xhr.responseText); | ||
} | ||
}; | ||
xhr.send(null); | ||
} | ||
}; | ||
|
||
var tail = function () { | ||
var uri = '/tail?offset=' + offset; | ||
const tail = function () { | ||
const uri = '/tail?offset=' + offset; | ||
request(uri, append); | ||
} | ||
}; | ||
|
||
var refresh = function () { | ||
const refresh = function () { | ||
tail(); | ||
if (polling == null) { | ||
var interval = parseInt(param('interval', 3000)); | ||
const interval = parseInt(param('interval', 3000)); | ||
polling = window.setInterval(tail, interval); | ||
} | ||
} | ||
}; | ||
|
||
var sleep = function () { | ||
const sleep = function () { | ||
if (polling != null) { | ||
window.clearInterval(polling); | ||
polling = null; | ||
} | ||
} | ||
}; | ||
|
||
window.onload = refresh; | ||
window.onfocus = refresh; | ||
window.onblur = sleep; | ||
</script> | ||
</head> | ||
<body style="background: black; color: #ddd; margin: 0px;"> | ||
<pre id="tail" style="white-space: pre-wrap; margin: 0px; height: 100%; overflow: auto;"></pre> | ||
<body style="background: black; color: #ddd; margin: 0;"> | ||
<pre id="tail" style="white-space: pre-wrap; margin: 0; height: 100%; overflow: auto;"></pre> | ||
</body> | ||
</html> |