forked from gm3197/WebBuzzer
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmanage.js
More file actions
54 lines (51 loc) · 1.93 KB
/
manage.js
File metadata and controls
54 lines (51 loc) · 1.93 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
// Initialize Firebase
var config = {
apiKey: "AIzaSyCXXkD7eV5z7mU-mM6IdEL5ELS9I-azC5c",
authDomain: "my-portfolio-55268.firebaseapp.com",
databaseURL: "https://my-portfolio-55268.firebaseio.com",
projectId: "my-portfolio-55268",
storageBucket: "my-portfolio-55268.appspot.com",
messagingSenderId: "897895059048"
};
firebase.initializeApp(config);
if (QueryString().id != "") {
var room = firebase.database().ref('webBuzzer/' + QueryString().id)
room.child('name').once('value', function(name) {
document.getElementById('title').innerHTML = "<u>Manage Web Buzzer</u><br> " + name.val()
document.getElementById('instructions').innerHTML = "Give your players this code: " + QueryString().id
})
room.child('mostRecentBuzz').on('value', function(data) {
if (data.val() == 0) {
document.getElementById('mostRecentBuzz').innerHTML = "Waiting for Buzz"
} else {
room.child('people').child(data.val()).once('value', function(name) {
document.getElementById('mostRecentBuzz').innerHTML = name.val()
})
}
})
} else {
window.open('index.html', '_self')
}
function resetBuzz() {
firebase.database().ref('webBuzzer/' + QueryString().id + '/mostRecentBuzz').set(0)
}
function QueryString() {
var query_string = {};
var query = window.location.search.substring(1);
var vars = query.split("&");
for (var i=0;i<vars.length;i++) {
var pair = vars[i].split("=");
// If first entry with this name
if (typeof query_string[pair[0]] === "undefined") {
query_string[pair[0]] = decodeURIComponent(pair[1]);
// If second entry with this name
} else if (typeof query_string[pair[0]] === "string") {
var arr = [ query_string[pair[0]],decodeURIComponent(pair[1]) ];
query_string[pair[0]] = arr;
// If third or later entry with this name
} else {
query_string[pair[0]].push(decodeURIComponent(pair[1]));
}
}
return query_string;
}