-
Notifications
You must be signed in to change notification settings - Fork 0
/
kwitter_room.js
50 lines (43 loc) · 1.76 KB
/
kwitter_room.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
const firebaseConfig = {
apiKey: "AIzaSyBMmZdkkv5fSokKZU9HzHMStD9GkWAwMnI",
authDomain: "letschat-b5cb2.firebaseapp.com",
databaseURL: "https://letschat-b5cb2-default-rtdb.firebaseio.com",
projectId: "letschat-b5cb2",
storageBucket: "letschat-b5cb2.appspot.com",
messagingSenderId: "971294341197",
appId: "1:971294341197:web:50c0dc9343a26bf2f34404"
};
// Initialize Firebase
firebase.initializeApp(firebaseConfig);
function AddUser() {
user_name=document.getElementById("user_name").value;
firebase.database().ref("/").child(user_name).update({
purpose:"adding user"});
}
user_name=localStorage.getItem("user_name");
document.getElementById("user_name").innerHTML="Welcome " + user_name + "!";
function addRoom() {
room_name = document.getElementById("room_name").value;
firebase.database().ref("/").child(room_name).update({ purpose : "adding room name" })
localStorage.setItem("room_name", room_name);
window.location="kwitter_page.html";
}
function LogOut() {
localStorage.removeItem("user_name");
localStorage.removeItem("room_name");
window.location="kwitter_page.html";
}
function getData() {firebase.database().ref("/").on('value', function(snapshot) {document.getElementById("output").innerHTML = "";snapshot.forEach(function(childSnapshot) {childKey = childSnapshot.key;
Room_names = childKey;
//Start code
console.log(Room_names);
row = "<div class='room_name' id="+Room_names+" onclick='redirectToRoomName(this.id)' >#"+ Room_names +"</div><hr>";
document.getElementById("output").innerHTML+=row;
//End code
});});}
getData();
function redirectToRoomName(name) {
console.log(name);
localStorage.setItem("room_name", name);
window.location="kwitter_page.html";
}