-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfirebase.js
52 lines (46 loc) · 2.24 KB
/
firebase.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
// import { initializeApp } from "https://www.gstatic.com/firebasejs/9.6.1/firebase-app.js";
import("https://www.gstatic.com/firebasejs/9.6.1/firebase-app.js").then(
(firebase) => {
const firebaseConfig = {
apiKey: "AIzaSyBmNN3Zt0jfel1UTzb5pF-df0QLBCGjm9M",
authDomain: "synchro-42865.firebaseapp.com",
projectId: "synchro-42865",
storageBucket: "synchro-42865.appspot.com",
messagingSenderId: "115204736345",
appId: "1:115204736345:web:bfaaf98c0003872dc53848",
measurementId: "G-76WWP2JG74"
};
const app = firebase.initializeApp(firebaseConfig);
import("https://www.gstatic.com/firebasejs/9.6.1/firebase-database.js").then(
(module) => {
chrome.runtime.onMessage.addListener((msg, sender, response) => {
console.log(msg);
if(msg.command == 'AddInteraction'){
try{
const db = module.getDatabase();
const InteractionsCount = module.ref(db, 'Interactions');
module.get(InteractionsCount).then((snapshot) => {
var data = parseInt(snapshot.val());
data += 1;
module.set(module.ref(db), {
'Interactions': data
});
}).catch((error) => {
console.log("firebase.js: " + error);
});
const UserCount = module.ref(db, 'users/');
module.get(UserCount).then((snapshot) => {
allUsercounts = snapshot.val();
var beginningUserObj = msg.data;
allUsercounts[msg.nodeName] = beginningUserObj;
module.set(module.ref(db, 'users/'),allUsercounts);
});
}catch(e){
console.log("firebase.js: " + e);
}
}
});
}
)
}
)