This repository has been archived by the owner on Feb 18, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
87 lines (74 loc) · 2.84 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
function sendMessage(){
var input = document.getElementById('userinput');
if(input.value == ""){
return;
}else{
var xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status != 200) {
alert('Shit Dud, Error Occured');
}
};
xmlhttp.open("GET", "php/functions/func_exec.php?function=sendMessage&room="+ parseInt(document.getElementById('roomName').dataset.roomid) +"&msg=" + input.value, true);
xmlhttp.send();
};
input.value = "";
var ifrm = document.getElementById('messagesIframe');
ifrm.src = ifrm.src;
setTimeout(function(){
document.getElementById('messagesIframe').contentWindow.scrollTo( 0, 999999 );
},500);
};
function joinRoom(){
var roomid = prompt("Please enter the room id you wish to join!");
var xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status != 200) {
alert('Shit Dud, Error Occured');
}
};
xmlhttp.open("GET", "php/functions/func_exec.php?function=joinRoom&room="+roomid, true);
xmlhttp.send();
location.reload();
}
function leaveRoom(){
var roomList = document.getElementById('roomListSelect');
var roomid = roomList[roomList.selectedIndex].dataset.roomid;
var xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status != 200) {
alert('Shit Dud, Error Occured');
}
};
xmlhttp.open("GET", "php/functions/func_exec.php?function=leaveRoom&room="+parseInt(roomid), true);
xmlhttp.send();
location.reload();
}
function createRoom(){
var name = prompt("Please enter the room name");
var img = prompt("Please enter the img URL or leave blank for the default one");
var xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status != 200) {
alert('Shit Dud, Error Occured');
}
};
xmlhttp.open("GET", "php/functions/func_exec.php?function=createRoom&name="+name+"&img="+img, true);
xmlhttp.send();
location.reload();
}
function MsgKeyDown(event){
switch (true){
case !event.altKey && !event.ctrlKey && !event.shiftKey && event.key == "Enter":
sendMessage();
break;
}
}
function validateEmail(input){
var regex = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
if(!regex.test(input.value)){
input.style.border = "2px solid red";
}else{
input.style.border = "1px solid rgba(0,0,0,.3)";
}
}