-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjavaengine.js
More file actions
68 lines (48 loc) · 1.29 KB
/
javaengine.js
File metadata and controls
68 lines (48 loc) · 1.29 KB
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
(function() {
var getNode = function(s) {
return document.querySelector(s);
},
// Get Nodes
status = getNode(".chat-status span"),
textarea = getNode(".chat textarea"),
chatName = getNode(".chat-name"),
messages = getNode(".chat-messages"),
roomName = getNode(".room-name");
statusDefault = status.textContent,
setStatus = function(s) {
status.textContent =s;
if(s !== statusDefault){
var delay = setTimeout(function() {
setStatus(statusDefault);
clearInterval(delay)
}, 3000);
}
};
try {
var socket = io.connect("http://88.192.20.97:6060");
} catch(e) {
// Set status to not connected
}
if(socket !== undefined) {
// Listen for status
socket.on("status", function(data){
setStatus((typeof data === "object") ? data.message : data);
if(data.clear === true){
textarea.value = "";
}
});
// Event listener
textarea.addEventListener("keydown", function(event){
var self = this,
name = chatName.value;
room = roomName.value;
if(event.which === 13 && event.shiftKey === false){
socket.emit("input", {
name: name,
message: self.value,
room: room
});
}
});
}
})();