mirror of
https://github.com/TangentFoxy/lovebird.git
synced 2025-07-28 11:02:19 +00:00
Added getPage() JS function to index page
This commit is contained in:
30
lovebird.lua
30
lovebird.lua
@@ -127,6 +127,20 @@ end
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var getPage = function(url, onComplete, onFail) {
|
||||||
|
var req = new XMLHttpRequest();
|
||||||
|
req.onreadystatechange = function() {
|
||||||
|
if (req.readyState != 4) return;
|
||||||
|
if (req.status == 200) {
|
||||||
|
onComplete(req.responseText)
|
||||||
|
} else {
|
||||||
|
onFail(req.responseText)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
req.open("GET", url + "?_=" + Math.random(), true);
|
||||||
|
req.send();
|
||||||
|
}
|
||||||
|
|
||||||
/* Scroll output to bottom */
|
/* Scroll output to bottom */
|
||||||
var scrolloutput = function() {
|
var scrolloutput = function() {
|
||||||
var div = document.getElementById("output");
|
var div = document.getElementById("output");
|
||||||
@@ -136,21 +150,17 @@ end
|
|||||||
|
|
||||||
/* Refresh output buffer and status */
|
/* Refresh output buffer and status */
|
||||||
var refresh = function() {
|
var refresh = function() {
|
||||||
var req = new XMLHttpRequest();
|
getPage("/buffer",
|
||||||
req.onreadystatechange = function() {
|
function(text) {
|
||||||
if (req.readyState != 4) return;
|
|
||||||
if (req.status == 200) {
|
|
||||||
updateDivContent("status", "connected ●");
|
updateDivContent("status", "connected ●");
|
||||||
if (updateDivContent("output", req.responseText)) {
|
if (updateDivContent("output", text)) {
|
||||||
scrolloutput();
|
scrolloutput();
|
||||||
}
|
}
|
||||||
} else {
|
},
|
||||||
|
function(text) {
|
||||||
updateDivContent("status", "disconnected ○");
|
updateDivContent("status", "disconnected ○");
|
||||||
}
|
}
|
||||||
}
|
);
|
||||||
/* Random used to avoid IE's caching */
|
|
||||||
req.open("GET", "/buffer?_=" + Math.random(), true);
|
|
||||||
req.send();
|
|
||||||
}
|
}
|
||||||
setInterval(refresh, <?lua echo(lovebird.refreshrate) ?> * 1000);
|
setInterval(refresh, <?lua echo(lovebird.refreshrate) ?> * 1000);
|
||||||
</script>
|
</script>
|
||||||
|
Reference in New Issue
Block a user