This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<meta name="viewport" content="width=device-width, initial-scale=1"> | |
<title>ComputasBrann Notes</title> | |
<!-- update the version number as needed --> | |
<script defer src="/__/firebase/4.8.0/firebase.js"></script> | |
<!-- include only the Firebase features as you need --> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
service cloud.firestore { | |
match /databases/{database}/documents { | |
match /notes/{doc} { | |
allow list: if false; | |
allow get: if true; | |
allow create: if true; | |
allow delete: if true; | |
allow update: if true; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// https://stackoverflow.com/a/2117523 | |
function uuidv4() { | |
return ([1e7]+-1e3+-4e3+-8e3+-1e11).replace( | |
/[018]/g, | |
c => (c ^ crypto.getRandomValues(new Uint8Array(1))[0] & 15 >> c / 4).toString(16) | |
); | |
} | |
document.addEventListener('DOMContentLoaded', function() { | |
// // 🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// https://stackoverflow.com/a/2117523 | |
function uuidv4() { | |
return ([1e7]+-1e3+-4e3+-8e3+-1e11).replace( | |
/[018]/g, | |
c => (c ^ crypto.getRandomValues(new Uint8Array(1))[0] & 15 >> c / 4).toString(16) | |
); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
html{ | |
background: #CCC; | |
font-family: Monaco, monospace; | |
font-size: 14px; | |
color: #444; | |
line-height: 1.4; | |
max-width: 60rem; | |
margin: 0 auto; | |
height: 100%; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
noteId = window.location.hash; // was h | |
project = "computasbrann-example"; | |
// f = firebase | |
firebase.initializeApp({ | |
authDomain:project+".firebaseapp.com", | |
projectId:project | |
}); | |
var dbClient=null; | |
var uuid = uuidv4(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
noteElement = document.getElementById("note"); | |
noteDocument = dbClient.collection("notes").doc(noteId); | |
noteElement.oninput = function(){ | |
noteDocument.set({ | |
owner: uuid, | |
text: this.innerHTML | |
}); | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
noteDocument.set({owner:0}, {merge: true}); | |
noteDocument.onSnapshot(function(documentSnapshot){ | |
noteData = documentSnapshot.data(); | |
if(noteData.owner !== uuid ) { | |
noteElement.innerHTML = noteData.text || ''; | |
} | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<meta name="viewport" content="width=device-width, initial-scale=1"> | |
<title>ComputasBrann Notes</title> | |
<!-- update the version number as needed --> | |
<script defer src="/__/firebase/4.8.0/firebase.js"></script> | |
<!-- include only the Firebase features as you need --> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var user = null; | |
var provider = new firebase.auth.GoogleAuthProvider(); | |
firebase.auth().useDeviceLanguage(); | |
firebase.auth().signInWithPopup(provider).then(function(result) { | |
user = result.user; | |
// All the Firestore code with 'enablePersistence()' goes here |
OlderNewer