-
Notifications
You must be signed in to change notification settings - Fork 0
/
chat.html
85 lines (80 loc) · 3.36 KB
/
chat.html
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" >
<meta name="viewport" content="width=device-width, initial-scale=1.0" >
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<link href="https://fonts.googleapis.com/css2?family=Press+Start+2P&display=swap" rel="stylesheet">
<link rel="icon" type="image/jpg" href="imgs/www.png">
<link rel="stylesheet" href="css/form_style.css">
<link rel="stylesheet" href="css/style.css">
<title>Contact us</title>
<script src="https://www.gstatic.com/firebasejs/7.17.1/firebase.js"></script>
<script>
const mainConfig = {
apiKey: "AIzaSyBKTjTMy2Trfs79UHuXHOrgFKSAEQnUYV4",
authDomain: "vent-92591.firebaseapp.com",
databaseURL: "https://vent-92591-default-rtdb.asia-southeast1.firebasedatabase.app",
projectId: "vent-92591",
storageBucket: "vent-92591.appspot.com",
messagingSenderId: "832851875687",
appId: "1:832851875687:web:7b3acbe6da4a15371b01c2"
};
// Initialize Firebase
firebase.initializeApp(mainConfig);
var myName = prompt("Enter your real name");
var email = prompt("Enter your email address");
var atposition=email.indexOf("@");
var dotposition=email.lastIndexOf(".");
if (atposition<1 || dotposition<atposition+2 || dotposition+2>=email.length){
alert("Please enter a valid e-mail address");
setTimeout(window.open('chat.html', '_self'),100);
}
//send message to Firebase
function sendMessage() {
// get message
var message = document.getElementById("message").value;
document.getElementById("message").value = "";
// save in DB
firebase.database().ref("messages").push().set({
"sender": myName,
"message": message,
"email":email
});
// prevent submit
return false;
}
//Storage msg
firebase.database().ref("messages").on("child_added", function (snapshot) {
var html = "";
html += snapshot.val().sender + ": " + snapshot.val().message;
html += "\n";
document.getElementById("messages").innerHTML += html;
});
</script>
<style type="text/css">
textarea{
padding: 0.5rem;
resize: none;
}
input{
font-family:'Courier New', Courier, monospace;
}
</style>
</head>
<body style="background-color:rgb(0, 0, 0)">
<div style="display:inline-block;text-align: center;">
<p style="color:white">In_Dev Chat-box</p><br>
<textarea id="messages" rows="20" cols="30" style="background-color:black;color:white;border-radius:0.2rem" readonly></textarea>
<br>
<code style="color:rgb(196, 181, 181);padding: 0.3rem;">Scroll to bottom for new messages</code>>
<br>
<form onsubmit="return sendMessage();" style="padding: 0.5rem;">
<input id="message" placeholder="Enter message" autocomplete="off" style="padding: 0.2rem">
<button class="btn" style="background-color: black;border-style: solid;border-width: 1px;color:white;padding: 0.2rem;font-size:2vh;font-family:'Courier New', Courier, monospace" onclick="return sendMessage();">cancel</button>
</form>
</div>
</body>
</html>