Skip to content

Instantly share code, notes, and snippets.

@TheCodingLady
Created April 17, 2018 06:26
Show Gist options
  • Save TheCodingLady/81095db5446f73b1cdf2d5ea7a202869 to your computer and use it in GitHub Desktop.
Save TheCodingLady/81095db5446f73b1cdf2d5ea7a202869 to your computer and use it in GitHub Desktop.
QUETE1-Firebase-SDK
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>Quete Walking Dead</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body>
<h1 class="pagetitle">La Loupe Registry of Known Zombies</h1>
<form>Enter the zombie's name:
<br>
<input id="Name" type="text" name="name" placeholder="ex. Martine Potiron" size="55" maxlength="53">
<br>
<br/>
<button onClick="submitClick()" type="button">ADD TO LIST</button>
</form>
<div>
<ul id="list-zombies">
</ul>
</div>
<script src="https://www.gstatic.com/firebasejs/4.12.1/firebase.js"></script>
<script>
const config = {
apiKey: "AIzaSyCyMtWFjmNS-TS48G8N50RxlMcEeRvg0tA",
authDomain: "quete-sdk-firebase-walkingdead.firebaseapp.com",
databaseURL: "https://quete-sdk-firebase-walkingdead.firebaseio.com",
projectId: "quete-sdk-firebase-walkingdead",
storageBucket: "quete-sdk-firebase-walkingdead.appspot.com",
messagingSenderId: "350600630284"
};
firebase.initializeApp(config);
</script>
<script src="index.js"></script>
</body>
</html>
// Initialize Firebase
window.alert("Beware of the ZOMBIES!");
var db = firebase.database();
const ref = db.ref("zombies");
ref.on("value", function (snapshot) {
document.getElementById('list-zombies').innerHTML="";
snapshot.forEach(function (childSnapshot) {
let childData = childSnapshot.val();
console.log(childSnapshot.val());
document.getElementById('list-zombies').innerHTML += '<li>' + childData.name + '</li>';
});
});
function writeUserData(Name) {
db.ref('zombies/' + name).push({
name: Name,
});
}
function submitClick() {
let name = document.getElementById("Name").value;
writeUserData(name);
window.alert("Beware! Zombie population increasing.");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment