mirror of
https://github.com/paradoxxxzero/butterfly.git
synced 2026-05-26 23:19:43 +00:00
42 lines
1019 B
JavaScript
42 lines
1019 B
JavaScript
// Generated by CoffeeScript 1.6.3
|
|
var ws;
|
|
|
|
ws = null;
|
|
|
|
$(function() {
|
|
ws = new WebSocket('ws://' + document.location.host + '/ws');
|
|
ws.onopen = function() {
|
|
return console.log("WebSocket open", arguments);
|
|
};
|
|
ws.onclose = function() {
|
|
return console.log("WebSocket closed", arguments);
|
|
};
|
|
ws.onerror = function() {
|
|
return console.log("WebSocket error", arguments);
|
|
};
|
|
ws.onmessage = function(event) {
|
|
return $('.term code').html($('.term code').html() + event.data);
|
|
};
|
|
return $('html,body').on('keypress', function(event) {
|
|
var code;
|
|
code = event.keyCode;
|
|
ws.send(String.fromCharCode(code));
|
|
event.preventDefault();
|
|
event.stopPropagation();
|
|
return false;
|
|
}).on('keydown', function(event) {
|
|
var code;
|
|
code = event.keyCode;
|
|
if (code === 17) {
|
|
return;
|
|
}
|
|
if (event.ctrlKey) {
|
|
code -= 64;
|
|
ws.send(String.fromCharCode(code));
|
|
event.preventDefault();
|
|
event.stopPropagation();
|
|
return false;
|
|
}
|
|
});
|
|
});
|