<script>document.addEventListener("DOMContentLoaded",function(){window.signInEmail="<%= userEmail %>";window.currentNote="",window.editor={id:"",title:"",description:""},console.log("<%= userEmail %>"),firebase.database().ref("<%= userEmail %>").orderByChild("timestamp").on("value",function(e){var t=[];e.forEach(function(e){var o=e.key,a=e.val();t.push({childKey:o,childData:a})}),t.reverse(),window.notesData={};var o=document.getElementById("note-family");if(o.innerHTML="",noteFamilyString="",t.forEach(function(e){var t=e.childKey,o=e.childData;noteFamilyString+='<div id="'+t+'" class="note-row hoverable" onclick=doOnNoteClick(this) ><div class="note-title">'+o.title+'</div><div class="note-date">'+o.date+"</div></div>",window.notesData[t]={description:o.description,title:o.title}}),o.innerHTML=noteFamilyString,window.currentNote)try{document.getElementById(window.currentNote).classList.add("is--active"),document.getElementById(window.currentNote).classList.remove("hoverable")}catch(e){console.log("Ignore this error, comes at time of delete",e.toString)}}),addNotefunction=((e,t)=>{console.log("Add Note");var o={title:e,description:t,date:(new Date).toLocaleDateString("en-US",{month:"short",day:"numeric"}),timestamp:firebase.database.ServerValue.TIMESTAMP},a=firebase.database().ref("<%= userEmail %>").push().key;console.log(a),window.currentNote=a;var n={};return n[a]=o,firebase.database().ref("<%= userEmail %>").update(n)}),updateNotefunction=((e,t,o)=>{console.log("Update Note");var a={title:t,description:o,date:(new Date).toLocaleDateString("en-US",{month:"short",day:"numeric"}),timestamp:firebase.database.ServerValue.TIMESTAMP},n={};return n[e]=a,firebase.database().ref("<%= userEmail %>").update(n)}),deleteNotefunction=(e=>firebase.database().ref("<%= userEmail %>").child(e).remove())}),signOutFromGoogle=(()=>{saveForUnSavedChanges(),console.log("Sign Out User!");firebase.auth().signOut();var e=new XMLHttpRequest;e.addEventListener("error",function(e){console.log("Failed"),console.log(e.toString())}),e.addEventListener("load",function(e){console.log("Sign Out Success!"),location.reload()}),e.open("POST","/clear",!0),e.setRequestHeader("Content-Type","application/json"),e.send()});</script>
0 commit comments