70 lines
1.7 KiB
JavaScript
70 lines
1.7 KiB
JavaScript
var http_in = new XMLHttpRequest();
|
|
var http_out = new XMLHttpRequest();
|
|
var offset = 0;
|
|
var lines = 25;
|
|
|
|
get_output();
|
|
var chan=""
|
|
chan=window.location.hash.substr(1);
|
|
if (chan == "") {chan="SERVER";}
|
|
else {chan="#"+chan;};
|
|
var channel=chan
|
|
|
|
function sleep(milliseconds) {
|
|
var start = new Date().getTime();
|
|
for (var i = 0; i < 1e7; i++) {
|
|
if ((new Date().getTime() - start) > milliseconds){
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
function out_event() {
|
|
setTimeout(function() {
|
|
if (http_out.readyState == 4) {
|
|
if (http_out.status != 500) {
|
|
// var len = parseInt(http_out.getResponseHeader("Content-Length"));
|
|
var len = 0;
|
|
// offset += isNaN(len) ? 0 : len;
|
|
offset = 0;
|
|
out_area = document.getElementById("out");
|
|
out_area.value += http_out.responseText;
|
|
out_area.scrollTop = out_area.scrollHeight;
|
|
}
|
|
|
|
// sleep(500);
|
|
get_output();
|
|
chan="";chan=window.location.hash.substr(1);
|
|
if (chan == "") {chan="SERVER";}
|
|
else {chan="#"+chan;};
|
|
console.log("selected channel: "+chan);
|
|
channel=chan;
|
|
}
|
|
},500)}
|
|
|
|
function get_output() {
|
|
setTimeout(function() {
|
|
http_out.onreadystatechange = out_event;
|
|
// range = "bytes=" + offset.toString() + "-";
|
|
http_out.open("GET", "/cgi-bin/out.cgi"+"?channel="+encodeURIComponent(channel)+"&lines="+encodeURIComponent(lines), true);
|
|
// http_out.setRequestHeader("Range", range);
|
|
http_out.send();
|
|
},10)}
|
|
|
|
function submit_input() {
|
|
var msg = document.getElementById("in").value + '\n';
|
|
document.getElementById("in").value = "";
|
|
http_in.open("POST", "/cgi-bin/in.cgi", true);
|
|
http_in.send(msg);
|
|
}
|
|
|
|
function key(e) {
|
|
if (e.keyCode == 13)
|
|
submit_input();
|
|
}
|
|
|
|
window.onload = function(e) {
|
|
document.getElementById("in").onkeyup = key;
|
|
get_output();
|
|
}
|