-
Notifications
You must be signed in to change notification settings - Fork 0
/
background.js
executable file
·62 lines (54 loc) · 1.64 KB
/
background.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
53
54
55
56
57
58
59
60
61
62
/* global chrome firebase getUid timeStamp */
/* eslint-disable no-unused-vars */
let actionNum = 1;
// Initialize Firebase
const dbConfig = {
apiKey: "AIzaSyBYp8MTp3AzU5itbJTTq-MR-9BYNbPZ6ic",
databaseURL: "https://linkedintemplater.firebaseio.com",
projectId: "linkedintemplater",
};
firebase.initializeApp(dbConfig);
// Send anonymous logging to improve user experience
function logActionDB(action) { // eslint-disable-line no-unused-vars
return getUid().then(({ uid, newUser }) => {
const logData = {
uid,
time: Date.now(),
date: timeStamp(),
action,
actionNum,
};
const key = `${logData.uid}/${logData.time} - ${logData.action}`;
if (newUser) {
logActionDB("Generated new UID");
}
firebase.database().ref(`logs/${key}`).set(logData);
// Increase action number for the current session
// which begins when the extension is enabled
actionNum++;
});
}
const showOptions = () => {
chrome.runtime.openOptionsPage();
};
chrome.extension.onRequest.addListener(
function (request, sender, sendResponse) {
if (request.msg === "showOptions") {
// see content.js -> runV2()
showOptions();
} else if (request.msg === "logAct") {
// see js/content.js -> logAction()
logActionDB(request.action);
}
}
);
chrome.runtime.onInstalled.addListener(function (details) {
if (details.reason == "install") {
logActionDB("Installed extension");
showOptions();
} else if (details.reason == "update") {
logActionDB("Updated extension");
}
});
const uninstallSurveyUrl = "https://goo.gl/eRgXvg";
chrome.runtime.setUninstallURL(uninstallSurveyUrl);