-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDBtest.html
120 lines (100 loc) · 3.32 KB
/
DBtest.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
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
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<script src="https://www.gstatic.com/firebasejs/3.6.5/firebase.js"></script>
<script>
// Initialize Firebase
var config = {
apiKey: "AIzaSyBuyYBVU2njsCHe4PkLD1RVtRChgnO1kLc",
authDomain: "slimeqq-database.firebaseapp.com",
databaseURL: "https://slimeqq-database.firebaseio.com",
storageBucket: "slimeqq-database.appspot.com",
messagingSenderId: "514777325203"
};
firebase.initializeApp(config);
</script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.0.0/jquery.js"></script>
<style type="text/css">
#game {
position: absolute;
top: 0px;
left: 0px;
width: 100%;
height: auto;
text-align: middle;
}
#game canvas{
margin: auto auto;
}
#debug {
white-space:pre;
position: absolute;
top: 600px;
left: 200px;
width: 100%;
height: auto;
text-align: middle;
}
.showdiv {
white-space:pre;
text-align: center;
width: 100%;
height: auto;
}
</style>
</head>
<body>
<div>
Name:<input type="text" id="name"><br>
LV:<input type="text" id="lv"><br>
x:<input type="number" id="pointX">,y:<input type="number" id="pointY"><br>
<input type="button" id="send" value="新增"><input type="button" id="remove" value="移除">
</div>
<div class="showdiv" id="show"></div>
<div class="showdiv" id="show2"></div>
<div class="showdiv" id="show3"></div>
<div class="showdiv" id="show4"></div>
<script type="text/javascript">
var database = firebase.database();
//$('#show4').text = '';
firebase.database().ref('DBtest').on('value',function(snapshot) {
var str = 'show4\n';
snapshot.forEach(function(item) {
str += 'first name: '+ item.key +'\n,name:' +item.val().name +',lv: '+item.val().lv+',x:'+item.val().point.X+',y:'+item.val().point.Y+'\n';
});
$('#show4').text(str);
});
/*forEach(function(item) {
str += 'first name: '+ item.name() +'\n,name:' +item.val().name +',lv: '+item.val().lv+',x:'+item.val().point.X+',y:'+item.val().point.Y+'\n';
});*/
$("#send").click(function(){
var name = $('#name').val();
var lv = $('#lv').val();
var x = $('#pointX').val();
var y = $('#pointY').val();
firebase.database().ref('DBtest/'+name).set({
"name": name,
"lv": lv,
"point": {
"X": x,
"Y": y
}
});
});
$("#remove").click(function(){
var name = $('#name').val();
firebase.database().ref('DBtest/'+name).set(null);
});
firebase.database().ref('DBtest/').on('child_added',function(data) {
$('#show').text('show1\nname:'+data.val().name+',lv: '+data.val().lv+',x:'+data.val().point.X+',y:'+data.val().point.Y);
});
firebase.database().ref('DBtest/').on('child_changed',function(data) {
$('#show2').text('show2\nname:'+data.val().name+',lv: '+data.val().lv+',x:'+data.val().point.X+',y:'+data.val().point.Y);
});
firebase.database().ref('DBtest/').on('child_removed',function(data) {
$('#show3').text('show3\nname:'+data.val().name+',lv: '+data.val().lv+',x:'+data.val().point.X+',y:'+data.val().point.Y);
});
</script>
</body>
</html>