This repository was archived by the owner on Jul 22, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathchatapp.html
More file actions
137 lines (123 loc) · 5.39 KB
/
chatapp.html
File metadata and controls
137 lines (123 loc) · 5.39 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
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<!DOCTYPE html>
<html>
<head>
<title>Global Chat</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/malihu-custom-scrollbar-plugin/3.1.5/jquery.mCustomScrollbar.min.js"></script>
<link href="./public/neumorphism.css" rel="stylesheet" type="text/css">
<script src="https://kit.fontawesome.com/1da205bce6.js" crossorigin="anonymous"></script>
</head>
<body>
<main class="container ">
<div class="pl-50 pr-100">
<div class="p-3 p-md-2 mb-1 text-white rounded bg-dark mt-50">
<div class="col-md-6 py-20">
<h1 class="display-4 fst-italic">Chat App</h1>
</div>
</div>
</div>
</main>
<div class="container-fluid h-100">
<div class="row justify-content-center h-100">
<div class="col-md-8 col-xl-6 chat ">
<div class="card bg-primary shadow-inset text-center border-light p-3">
<div class="card-body msg_card_body " id="bodyContent">
</div>
<div class="card-footer">
<div class="input-group">
<div class="input-group-append">
<span class="input-group-text attach_btn"><i class="fas fa-envelope"></i></span>
</div>
<textarea name="message" id="message" class="form-control type_msg"
placeholder="Type your message..."></textarea>
<div class="input-group-append">
<button id="submit" class="input-group-text send_btn"><i class="fas fa-location-arrow"></i>
</button>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</body>
</html>
<script type="module">
// Import the functions you need from the SDKs you need
import {initializeApp} from "https://www.gstatic.com/firebasejs/9.6.6/firebase-app.js";
import {
getDatabase,
set,
ref,
push,
child,
onValue,
onChildAdded
} from "https://www.gstatic.com/firebasejs/9.6.6/firebase-database.js";
// TODO: Add SDKs for Firebase products that you want to use
// https://firebase.google.com/docs/web/setup#available-libraries
// Your web app's Firebase configuration
const firebaseConfig = {
apiKey: "AIzaSyCnAtB1sFxxAi8ENeaO3yb6HWBq0hA8KRQ",
authDomain: "codefury5.firebaseapp.com",
databaseURL: "https://codefury5-default-rtdb.firebaseio.com",
projectId: "codefury5",
storageBucket: "codefury5.appspot.com",
messagingSenderId: "113570483517",
appId: "1:113570483517:web:dff208550cf3840f0f8954",
measurementId: "G-DE6P68DBEF"
};
// Initialize Firebase
const app = initializeApp(firebaseConfig);
const database = getDatabase(app);
var myName = prompt("Enter your name");
submit.addEventListener('click', (e) => {
var message = document.getElementById('message').value;
var name = myName;
const id = push(child(ref(database), 'messages')).key;
set(ref(database, 'messages/' + id), {
name: name,
message: message
});
document.getElementById('message').value = "";
alert('message has sent');
});
const newMsg = ref(database, 'messages/');
onChildAdded(newMsg, (data) => {
if(data.val().name != myName) {
var divData = '<div class="d-flex justify-content-start mb-4" id="fromDiv">\n' +
' <div class="img_cont_msg">\n' +
' <img src=""\n' +
' class="rounded-circle user_img_msg">\n' +
' </div>\n' +
' <div class="msg_cotainer" >\n' +
' '+data.val().message+'' +
' <span class="msg_time"></span>\n' +
' </div>\n' +
' </div>';
var d1 = document.getElementById('bodyContent');
d1.insertAdjacentHTML('beforebegin', divData);
}else{
var divData = '<div class="d-flex justify-content-end mb-4">\n' +
' <div class="msg_cotainer_send" id="sendDiv">\n' +
' '+data.val().message+'' +
' <span class="msg_time_send">8:55 AM, Today</span>\n' +
' </div>\n' +
' <div class="img_cont_msg">\n' +
' <img src=""\n'+
' class="rounded-circle user_img_msg">\n' +
' </div>\n' +
' </div>';
var d1 = document.getElementById('bodyContent');
d1.insertAdjacentHTML('beforebegin', divData);
}
});
</script>
<script>
$(document).ready(function () {
$('#action_menu_btn').click(function () {
$('.action_menu').toggle();
});
});
</script>