-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
75 lines (66 loc) · 2.68 KB
/
index.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>firebase</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://www.gstatic.com/firebasejs/4.9.0/firebase.js"></script>
<script src="https://www.gstatic.com/firebasejs/4.6.2/firebase-app.js"></script>
<script src="https://www.gstatic.com/firebasejs/4.6.2/firebase-auth.js"></script>
<script src="https://www.gstatic.com/firebasejs/4.6.2/firebase-database.js"></script>
<script src="https://www.gstatic.com/firebasejs/4.6.2/firebase-messaging.js"></script>
<script>
// Menginisialisasi Firebase
var config = {
apiKey: "apiKey",
authDomain: "projectId.firebaseapp.com",
databaseURL: "https://databaseName.firebaseio.com",
projectId: "",
storageBucket: "bucket.appspot.com",
messagingSenderId: ""
};
firebase.initializeApp(config);
// Get a reference to the database service (Dapatkan referensi ke layanan database)
var database = firebase.database();
function writeUserData(userId, name, email, imageUrl) {
firebase.database().ref('users/' + userId).set({
username: name,
email: email,
profile_picture : imageUrl
});
};
function deleteData(id){
firebase.database().ref('/users/' + id).remove();
}
function updateData(id,name){
firebase.database().ref('/users/' + id).update({ username: name });
}
function writeData(name, email, imageUrl) {
var postData = {
username: name,
email: email,
profile_picture : imageUrl
};
// Get a key for a new Post.
var newPostKey = firebase.database().ref('users/').push().key;
// Write the new post's data simultaneously in the posts list and the user's post list.
var updates = {};
updates['/users/' + newPostKey] = postData;
firebase.database().ref().update(updates);
};
var commentsRef = firebase.database().ref('users/');
commentsRef.on('child_added', function(data) {
$("#boxchat").append("<div>"+data.val().username+"</div>");
});
commentsRef.on('child_changed', function(data) {
});
commentsRef.on('child_removed', function(data) {
});
</script>
</head>
<body>
<button value="set" onclick="writeUserData('4','diansuihanaa','dian@gmail','urlimg')">klik</button>
<button value="set" onclick="writeData('diansuihanaaa','dian@gmaila','urlimga')">klik</button>
<div id="boxchat"></div>
</body>
</html>