-
Notifications
You must be signed in to change notification settings - Fork 0
/
live.html
77 lines (64 loc) · 2.36 KB
/
live.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
<!DOCTYPE html>
<html>
<head>
<title>Live Log: M45-</title>
<style>
body {
background-color: #222;
color: #fff;
font-family: monospace;
font-weight: normal;
font-size: larger;
}
#log-data {
padding: 20px;
}
</style>
</head>
<body onload="onload()">
<div id="log-data">
<p id="loading-message">Loading...</p>
</div>
<script>
// Replace unix newlines with HTML newlines
function replaceNewlines(str) {
return str.replace(/\n/g, "<br>");
}
const htmlReg = new RegExp('<\\/?[a-z][a-z0-9]*[^<>]*>|<!--.*?-->', 'img')
const getPFolder = new RegExp('.*\\/current-logs\\/(.*)\\/live\\.html', '')
let lastLen = 0 //So we only scroll to bottom on new lines of text
// Define a function to remove the href and script tags from a given string
function removeHrefAndScriptTags(text) {
return text.replace(htmlReg, "");
}
// Load data from the specified URL and insert it into the page
function loadData(url) {
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function () {
if (this.readyState == 4 && this.status == 200) {
// Insert the data into the page
document.getElementById("log-data").innerHTML = replaceNewlines(removeHrefAndScriptTags(this.responseText));
// Scroll to the bottom of the page if there is new data
if (this.responseText.length > lastLen) {
lastLen = this.responseText.length
window.scrollTo(0, document.body.scrollHeight);
}
}
};
xhttp.open("GET", url, true);
xhttp.send();
}
// Automatically load new data from the specified URL every few seconds
setInterval(function () {
loadData("./newest.log");
}, 3000);
function onload() {
//Append server name to page title
var path = location.pathname;
var pfolder = path.match(getPFolder)[1]
document.title += pfolder.toUpperCase()
loadData("./newest.log");
};
</script>
</body>
</html>