|
45 | 45 | <!-- <script>var md=new Remarkable;function viewMobileSite(){window.location.href="/mobile"}document.addEventListener("DOMContentLoaded",function(){window.signInEmail="anonymousNotSigned";window.currentNote="",window.editor={id:"",title:"",description:""},console.log("anonymousNotSigned"),firebase.database().ref("anonymousNotSigned").orderByChild("timestamp").on("value",function(e){var o=[];e.forEach(function(e){var n=e.key,t=e.val();o.push({childKey:n,childData:t})}),o.reverse(),window.notesData={};var n=document.getElementById("note-family");if(n.innerHTML="",noteFamilyString="",o.forEach(function(e){var o=e.childKey,n=e.childData;noteFamilyString+='<div id="'+o+'" class="note-row hoverable" onclick=doOnNoteClick(this) ><div class="note-title">'+n.title+'</div><div class="note-date">'+n.date+"</div></div>",window.notesData[o]={description:n.description,title:n.title}}),n.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)}}),signInToGoogle=(()=>{console.log("Sign In to Google!");var e=new firebase.auth.GoogleAuthProvider;firebase.auth().signInWithPopup(e).then(function(e){console.log("success, check now!"),console.log(e.user);var o=new XMLHttpRequest;o.addEventListener("error",function(e){console.log("Failed"),console.log(e.toString())}),o.addEventListener("load",function(e){1==JSON.parse(e.srcElement.response).success?console.log("Sign In Success!"):console.log("Failed to sign In"),location.reload()}),o.open("POST","/set",!0),o.setRequestHeader("Content-Type","application/json"),o.send(JSON.stringify({userEmail:e.user.email,userDisplayName:e.user.displayName}))}).catch(function(e){console.log(e),console.log("Failed to do")})}),$("#sign-in-anonymous").click(function(){var e=new XMLHttpRequest;e.addEventListener("error",function(e){console.log("Failed"),console.log(e.toString())}),e.addEventListener("load",function(e){1==JSON.parse(e.srcElement.response).success?console.log("Sign In Success!"):console.log("Failed to sign In"),location.reload()}),e.open("POST","/set",!0),e.setRequestHeader("Content-Type","application/json"),e.send(JSON.stringify({userEmail:"anonymousUserPriyam",userDisplayName:"Priyam"}))})});</script> |
46 | 46 | <script></script> --> |
47 | 47 |
|
48 | | - <script> |
49 | | - var md = new Remarkable({ |
50 | | - html: true, |
51 | | - xhtmlOut: true |
52 | | - }); |
53 | | -
|
54 | | - document.addEventListener('DOMContentLoaded', function () { |
55 | | -
|
56 | | - // Taken from desktop part |
57 | | - window.signInEmail = 'anonymousNotSigned'; |
58 | | - const signInUserEmail = 'anonymousNotSigned'; |
59 | | - window.currentNote = ''; |
60 | | - window.editor = { id: '', title: '', description: '' }; |
61 | | -
|
62 | | - console.log(signInUserEmail); |
63 | | -
|
64 | | - // Now call the data extract for only once so as to get the list of datas |
65 | | - firebase.database().ref(signInUserEmail).orderByChild('timestamp').on('value', function (snapshot) { |
66 | | -
|
67 | | - //console.log(snapshot); |
68 | | - var descNoteList = []; |
69 | | -
|
70 | | - snapshot.forEach(function (childSnapshot) { |
71 | | - var childKey = childSnapshot.key; |
72 | | - var childData = childSnapshot.val(); |
73 | | - //console.log("childkey", childKey); |
74 | | - //console.log("childData", childData); |
75 | | - // ... |
76 | | - descNoteList.push({ childKey: childKey, childData: childData }); |
77 | | -
|
78 | | - }); |
79 | | -
|
80 | | - // Reverse the array |
81 | | - descNoteList.reverse(); |
82 | | -
|
83 | | - // Empty the notes data |
84 | | - window.notesData = {}; |
85 | | -
|
86 | | - var noteFamily = document.getElementById('note-family'); |
87 | | - noteFamily.innerHTML = ''; |
88 | | - noteFamilyString = ''; |
89 | | -
|
90 | | - descNoteList.forEach(function (childSnapshot) { |
91 | | - var childKey = childSnapshot.childKey; |
92 | | - var childData = childSnapshot.childData; |
93 | | -
|
94 | | - noteFamilyString += '<div id="' + childKey + '" class="note-row hoverable" onclick=doOnNoteClick(this) >' |
95 | | - + '<div class="note-title">' + childData.title + '</div>' |
96 | | - + '<div class="note-date">' + childData.date + '</div>' |
97 | | - + '</div>'; |
98 | | -
|
99 | | - // Only storing notes description in it |
100 | | - window.notesData[childKey] = { description: childData.description, title: childData.title }; |
101 | | - }); |
102 | | -
|
103 | | - noteFamily.innerHTML = noteFamilyString; |
104 | | -
|
105 | | - // make the current note active if present |
106 | | - if (window.currentNote) { |
107 | | - try { |
108 | | - document.getElementById(window.currentNote).classList.add('is--active'); |
109 | | - document.getElementById(window.currentNote).classList.remove('hoverable'); |
110 | | - } catch (e) { |
111 | | - console.log("Ignore this error, comes at time of delete", e.toString) |
112 | | - } |
113 | | - } |
114 | | -
|
115 | | -
|
116 | | - addNotefunction = (title, description) => { |
117 | | - //Start the add note function |
118 | | - console.log("Add Note"); |
119 | | -
|
120 | | - var options = { month: 'short', day: 'numeric' }; |
121 | | - var today = new Date(); |
122 | | - // console.log(today.toLocaleDateString("en-US", options)); |
123 | | -
|
124 | | - var newNote = { |
125 | | - title: title, |
126 | | - description: description, |
127 | | - date: today.toLocaleDateString("en-US", options), |
128 | | - timestamp: firebase.database.ServerValue.TIMESTAMP |
129 | | - } |
130 | | -
|
131 | | - // Get a key for a new Post. |
132 | | - var newPostKey = firebase.database().ref(signInUserEmail).push().key; |
133 | | -
|
134 | | - console.log(newPostKey); |
135 | | - // Now this is going to be the current value which we are editing |
136 | | - window.currentNote = newPostKey; |
137 | | -
|
138 | | - // Write the new post's data simultaneously in the posts list and the user's post list. |
139 | | - var updates = {}; |
140 | | - updates[newPostKey] = newNote; |
141 | | -
|
142 | | - return firebase.database().ref(signInUserEmail).update(updates); |
143 | | - } |
144 | | -
|
145 | | - updateNotefunction = (noteId, title, description) => { |
146 | | -
|
147 | | - //Start the update note function |
148 | | - console.log("Update Note"); |
149 | | -
|
150 | | - var options = { month: 'short', day: 'numeric' }; |
151 | | - var today = new Date(); |
152 | | - // console.log(today.toLocaleDateString("en-US", options)); |
153 | | -
|
154 | | - var newNote = { |
155 | | - title: title, |
156 | | - description: description, |
157 | | - date: today.toLocaleDateString("en-US", options), |
158 | | - timestamp: firebase.database.ServerValue.TIMESTAMP |
159 | | - } |
160 | | -
|
161 | | - // Write the new post's data simultaneously in the posts list and the user's post list. |
162 | | - var updates = {}; |
163 | | - updates[noteId] = newNote; |
164 | | -
|
165 | | - return firebase.database().ref(signInUserEmail).update(updates); |
166 | | - } |
167 | | -
|
168 | | - deleteNotefunction = (noteId) => { |
169 | | - return firebase.database().ref(signInUserEmail).child(noteId).remove(); |
170 | | - } |
171 | | -
|
172 | | - }); |
173 | | -
|
174 | | - //list(family); |
175 | | -
|
176 | | - // Here the firebase is correctly defined purely! |
177 | | - //console.log(firebase.database.ServerValue.TIMESTAMP); |
178 | | -
|
179 | | - // Removed the ones not needed here |
180 | | -
|
181 | | - signInToGoogle = () => { |
182 | | - // Start the sign in Activity! |
183 | | - console.log("Sign In to Google!"); |
184 | | -
|
185 | | - // Google sign in |
186 | | - var provider = new firebase.auth.GoogleAuthProvider(); |
187 | | - firebase.auth().signInWithPopup(provider).then(function (result) { |
188 | | - // console.log(result.user.email); |
189 | | - console.log("success, check now!"); |
190 | | -
|
191 | | - // console.log(result.user.displayName); |
192 | | - // console.log(result); |
193 | | - // console.log(result.user); |
194 | | - // console.log(result.user_id_token); |
195 | | -
|
196 | | - console.log(result.user); |
197 | | -
|
198 | | - // Add the cookie so that this can be also cleared whether to check wheather user is sign in or not |
199 | | - var xhttp = new XMLHttpRequest(); |
200 | | -
|
201 | | - xhttp.addEventListener("error", function (evt) { |
202 | | - console.log("Failed"); |
203 | | - console.log(evt.toString()); |
204 | | - }); |
205 | | -
|
206 | | - xhttp.addEventListener("load", function (evt) { |
207 | | -
|
208 | | - // console.log(evt); |
209 | | - // console.log(evt.srcElement); |
210 | | - // console.log(evt.srcElement.response); |
211 | | - if (JSON.parse(evt.srcElement.response)['success'] == 1) { |
212 | | - console.log("Sign In Success!"); |
213 | | - } else { |
214 | | - console.log("Failed to sign In"); |
215 | | - } |
216 | | - location.reload(); |
217 | | - }); |
218 | | -
|
219 | | - // Defining parameters |
220 | | - xhttp.open("POST", "/set", true); |
221 | | - //Send the proper header information along with the request |
222 | | - xhttp.setRequestHeader("Content-Type", "application/json"); // Necessary for POST |
223 | | - xhttp.send(JSON.stringify({ userEmail: result.user.email, userDisplayName: result.user.displayName })); |
224 | | -
|
225 | | - }).catch(function (err) { |
226 | | - console.log(err); |
227 | | - console.log("Failed to do"); |
228 | | - }); |
229 | | - } |
230 | | -
|
231 | | - }); |
232 | | -
|
233 | | - function viewMobileSite() { |
234 | | - window.location.href = "/mobile"; |
235 | | - } |
236 | | -
|
237 | | - // Add this sccript before the body to make this work |
238 | | -
|
239 | | - </script> |
| 48 | + <!-- Script just after body --> |
| 49 | + <script>var md=new Remarkable({html:!0,xhtmlOut:!0});function viewMobileSite(){window.location.href="/mobile"}document.addEventListener("DOMContentLoaded",function(){window.signInEmail="anonymousNotSigned";window.currentNote="",window.editor={id:"",title:"",description:""},console.log("anonymousNotSigned"),firebase.database().ref("anonymousNotSigned").orderByChild("timestamp").on("value",function(e){var o=[];e.forEach(function(e){var t=e.key,n=e.val();o.push({childKey:t,childData:n})}),o.reverse(),window.notesData={};var t=document.getElementById("note-family");if(t.innerHTML="",noteFamilyString="",o.forEach(function(e){var o=e.childKey,t=e.childData;noteFamilyString+='<div id="'+o+'" class="note-row hoverable" onclick=doOnNoteClick(this) ><div class="note-title">'+t.title+'</div><div class="note-date">'+t.date+"</div></div>",window.notesData[o]={description:t.description,title:t.title}}),t.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,o)=>{console.log("Add Note");var t={title:e,description:o,date:(new Date).toLocaleDateString("en-US",{month:"short",day:"numeric"}),timestamp:firebase.database.ServerValue.TIMESTAMP},n=firebase.database().ref("anonymousNotSigned").push().key;console.log(n),window.currentNote=n;var i={};return i[n]=t,firebase.database().ref("anonymousNotSigned").update(i)}),updateNotefunction=((e,o,t)=>{console.log("Update Note");var n={title:o,description:t,date:(new Date).toLocaleDateString("en-US",{month:"short",day:"numeric"}),timestamp:firebase.database.ServerValue.TIMESTAMP},i={};return i[e]=n,firebase.database().ref("anonymousNotSigned").update(i)}),deleteNotefunction=(e=>firebase.database().ref("anonymousNotSigned").child(e).remove())}),signInToGoogle=(()=>{console.log("Sign In to Google!");var e=new firebase.auth.GoogleAuthProvider;firebase.auth().signInWithPopup(e).then(function(e){console.log("success, check now!"),console.log(e.user);var o=new XMLHttpRequest;o.addEventListener("error",function(e){console.log("Failed"),console.log(e.toString())}),o.addEventListener("load",function(e){1==JSON.parse(e.srcElement.response).success?console.log("Sign In Success!"):console.log("Failed to sign In"),location.reload()}),o.open("POST","/set",!0),o.setRequestHeader("Content-Type","application/json"),o.send(JSON.stringify({userEmail:e.user.email,userDisplayName:e.user.displayName}))}).catch(function(e){console.log(e),console.log("Failed to do")})})});</script> |
240 | 50 |
|
241 | 51 | <div id="main"> |
242 | 52 | <div id="top-nav"> |
|
0 commit comments