-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfirebase.js
49 lines (40 loc) · 1.57 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
// Your web app's Firebase configuration
var firebaseConfig = {
apiKey: "AIzaSyCOnkmCgPHGCY9u2eb3yRwzCLNakg5a5O0",
authDomain: "sethacksextension.firebaseapp.com",
databaseURL: "https://sethacksextension.firebaseio.com",
projectId: "sethacksextension",
storageBucket: "sethacksextension.appspot.com",
messagingSenderId: "553965352661",
appId: "1:553965352661:web:6a0860fbb42a9f01b8d45c"
};
// Initialize Firebase
firebase.initializeApp(firebaseConfig);
console.log(firebase);
chrome.runtime.onMessage.addListener((msg, sender, response) => {
if(msg.command == "fetch"){
var domain = msg.data.domain;
var enc_domain = btoa(domain);
firebase.database().ref('/domain/'+enc_domain).once('value').then(function(snapshot){
response({type: "result", status: "success", data: snapshot.val(), request: msg});
});
}
if(msg.command == "post") {
var domain = msg.data.domain;
var enc_domain = btoa(domain);
var code = msg.data.code;
var desc = msg.data.desc;
try{
var newPost = firebase.database().ref('/domain/'+enc_domain).push().set({
code: code,
description: desc
});
var postId = newPost.key;
response({type: "result", status: "success", data: postId, request: msg});
}catch(e){
console.log('error', e);
response({type: "result", status: "error", data: e, request: msg});
}
}
return true;
})