-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
62 lines (52 loc) · 2.05 KB
/
script.js
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
document.getElementById("noteForm").addEventListener("submit", function(event) {
event.preventDefault();
const noteInput = document.getElementById("noteInput");
const notesContainer = document.getElementById("notesContainer");
const note = document.createElement("div");
note.className = "note";
note.textContent = noteInput.value;
notesContainer.appendChild(note);
noteInput.value = "";
});
document.getElementById("toggleDarkMode").addEventListener("click", function()
{
const body = document.querySelector("body");
body.classList.toggle("dark-mode");
});
const firebaseConfig = {
apiKey: "AIzaSyDhYaLPuhkEpjDAS8oAC1OoR9blnNL8ydo",
authDomain: "note-taking-website-5f173.firebaseapp.com",
databaseURL: "https://note-taking-website-5f173-default-rtdb.asia-southeast1.firebasedatabase.app",
projectId: "note-taking-website-5f173",
storageBucket: "note-taking-website-5f173.appspot.com",
messagingSenderId: "79500910698",
appId: "1:79500910698:web:c3b4806a9eed1464b66a13",
measurementId: "G-01DX3JT797"
};
firebase.initializeapp(firebaseConfig);
const database = firebase.database();
document.getElementById("noteForm").addEventListener("submit", function(event) {
event.preventDefault();
const noteInput = document.getElementById("noteInput");
const notesContainer = document.getElementById("notesContainer");
const note = document.createElement("div");
note.className = "note";
note.textContent = noteInput.value;
//save note to the database
database.ref("notes").push({
content: noteInput.value
});
notesContainer.appendChild(note);
noteInput.value = "";
});
function displayNote(content){
const notesContainer = document.getElementById("notesContainer");
const note = document.createElement("div");
note.className = "note";
note.textContent = content;
notesContainer.appendChild(note);
}
database.ref("notes").on("child_added", function(snapshot){
const noteContent = snapshot.val().content;
displayNote(noteContent);
});