-
Notifications
You must be signed in to change notification settings - Fork 18
/
main.js
97 lines (84 loc) · 2.41 KB
/
main.js
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
/* Copyright (c) 2015, Amperka LLC
*
* This software may be modified and distributed under the terms
* of the MIT license. See the LICENSE.txt file for details.
*/
Uint8Array.prototype.slice = function(begin, end) {
if (typeof begin === 'undefined') {
begin = 0;
}
if (typeof end === 'undefined') {
end = Math.max(this.length, begin);
}
var result = new Uint8Array(end - begin);
for (var i = begin; i < end; ++i) {
result[i - begin] = this[i];
}
return result;
}
function catBuffers(a, b) {
var result = new Uint8Array(a.length + b.length);
result.set(a);
result.set(b, a.length);
return result;
}
function uintToString(uintArray) {
var rawString = new TextDecoder().decode(uintArray),
processedString = removeEscSeq(rawString);
return processedString;
}
function removeEscSeq(rawString) {
//encode raw string to hex and remove escape sequence ">(zero or one times) CR ESC [ J"
var encodedString = encodeURIComponent(rawString).replace(/^(?:%3E)?%0D%1B%5BJ/gi, ""),
decodedString = decodeURIComponent(encodedString);
return decodedString;
}
function findLineBreak(b) {
for (var i = 0; i < b.length; ++i) {
if (b[i] == 10)
return i;
}
}
function handleBackspaces(s) {
var len;
do {
len = s.length;
s = s.replace(/[^\x08]\x08/, '');
} while (s.length != len);
return s;
}
function setText(txt) {
txt = handleBackspaces(txt);
$('h1').html(txt);
}
$(function() {
$('.btn-fullscreen').click(function(e) {
e.preventDefault();
var w = chrome.app.window.current();
if (w.isFullscreen()) {
w.restore();
} else {
w.fullscreen();
}
});
$(document).keyup(function(e) {
switch (e.which) {
case 122: // F11
case 70: // F
$('#menu .btn-fullscreen').trigger('click');
break;
case 121: // F10
$('#menu .btn-settings').trigger('click');
break;
case 112: // F1
$('#menu .btn-about').trigger('click');
break;
case 67: // C
$('#menu .btn-connection').trigger('click');
break;
case 32: // Space
$('#connection button:visible').trigger('click');
break;
}
});
});