-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdatacollection.html
More file actions
87 lines (73 loc) · 2.55 KB
/
Copy pathdatacollection.html
File metadata and controls
87 lines (73 loc) · 2.55 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
<html>
<body style="background-color:ghostwhite">
<script src="https://www.gstatic.com/firebasejs/5.7.2/firebase.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/0.7.2/p5.js"></script>
<!-- <script src="https://www.gstatic.com/firebasejs/5.0.0/firebase-database.js"></script>-->
<script>
var message,alldata,name;
var colors=['lightpink','lightgreen','lightblue','lightgray'];
var tr=false;
var config = {
apiKey: "AIzaSyBVxOLTli6ellP4gsRFnBKIVfyMn8d5F9c",
authDomain: "machine-7ca6e.firebaseapp.com",
databaseURL: "https://machine-7ca6e.firebaseio.com",
projectId: "machine-7ca6e",
storageBucket: "machine-7ca6e.appspot.com",
messagingSenderId: "355310789654"
};
firebase.initializeApp(config);
database = firebase.database();
function sendData(){
let colorDatabase = database.ref("colors");
//getting data starts here
colorDatabase.once("value",gotData);
function gotData(results){
let data=results.val();
let keys = Object.keys(data);
alldata={
entries:[]
};
for(let key of keys){
let record=data[key];
alldata.entries.push(record);
}
console.log(alldata.entries[0]);
for (let i=(alldata.entries.length-1);i>0;i--){
document.body.innerHTML+="<div style='position:relative;background-color:"+colors[Math.floor(Math.random()*colors.length)]+";border-radius: 26px;color:white'><p style='font-family:sans-serif;text-align:center'> name:"+alldata.entries[i]["name"]+"</p><br><p> <p><h3 style='font-family:sans-serif'>"+alldata.entries[i].message+"</h3><br></div>";
}
}//ends here
// Make an object with data in it
var data = {
message:message,
name:name
};
console.log("saving data");
console.log(data);
let color = colorDatabase.push(data, finished);
console.log("Firebase generated key: " + color.key);
tr=true;
// Reload the data for the page
function finished(err) {
if (err) {
console.error("ooops, something went wrong.");
console.error(err);
} else {
console.log('Data saved successfully');
}
}
}
function dataSend(){
let question =parseInt(prompt("do you want to leave a message?(1/0)"));
if(question===1){
message =prompt("your message...");
name=prompt("what is your name?");
sendData();
}
else{
sendData();
}
}
dataSend()
</script>
</body>
</html>