CliSite/website/script.js
2022-06-12 09:38:38 +02:00

75 lines
2.4 KiB
JavaScript

function addareacontent(content){
//this appends to the bottom of the console and scrolls to the bottom make sure we start typing at the bottom
var console = document.getElementById("console");
console.innerHTML = content;
console.scrollTop = console.scrollHeight;
}
function resizeit(){
$('#consolecont').css('height', $(window).height() - 10);
let height = ($(window).height() - $('#console').offset().top)*0.96;
$('#console').css('height', height);
$('#rows').val($(window).height() - $('#console').offset().top - 10);
}
$(document).ready(function(){
//fit console to screen
//$('#console').css('height', $(window).height() - $('#console').offset().top - 10);
//account for the input box
let host = 'ws://127.0.0.1:8480';
socket = io.connect(host);
resizeit();
//resize it on window resize
$(window).resize(function(){
resizeit();
});
//on key press on any part of html page
$("#console").keyup(function(e){
//if enter key is pressed
//get the input
e.preventDefault();
//resolve e.code to char
let key = e.which;
//send to server via socket if connected
if (key == 8){
socket.emit('keypress', key);
}
});
$("#console").keypress(function(e){
//if enter key is pressed
//get the input
e.preventDefault();
//resolve e.code to char
let key = e.which;
//send to server via socket if connected
socket.emit('keypress', key);
});
//connect to the server
//on connect
socket.on('connect', function(){
addareacontent("Connected to server");
});
//on disconnect
socket.on('disconnect', function(){
addareacontent("Disconnected from server");
});
//on error
socket.on('error', function(err){
addareacontent("Error: " + err);
});
//on message
socket.on('buffer', function(msg){
addareacontent(msg);
});
})
function flash(){
//if u+2800 is present in the console then replace it with 2588
let console = document.getElementById("console");
if(console.innerHTML.indexOf("\u2800") > -1){
console.innerHTML = console.innerHTML.replace("\u2800", "\u2588");
}
else{
console.innerHTML = console.innerHTML.replace("\u2588", "\u2800");
}
}
setInterval(flash, 500);