-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbackground.js
More file actions
58 lines (47 loc) · 2.28 KB
/
background.js
File metadata and controls
58 lines (47 loc) · 2.28 KB
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
chrome.runtime.onInstalled.addListener(function(details) {
const CLEAR_STORAGE_ON_UPDATE = false;
const ADVANCE_PROBLEM_ACTIVE_TIME = false;
const ADVANCE_PROBLEM_TIME_OBJ = {d:120, h:1, m:0, s:0};
if (CLEAR_STORAGE_ON_UPDATE) {
console.log("Clearing sync storage...");
chrome.storage.sync.clear();
console.log("sync storage cleared.");
} else {
chrome.storage.sync.get([constants.STORAGE_PROBLEM_COLLECTION], function(result) {
let problemCollectionObject = result[constants.STORAGE_PROBLEM_COLLECTION];
if (!result || !problemCollectionObject) {
console.error("lc-timer:setupSubmitScript: Error retrieving problems from storage.");
return null;
}
updateBadgeText(problemCollectionObject);
if(ADVANCE_PROBLEM_ACTIVE_TIME) {
// Advance problem active time for testing
for (var key in problemCollectionObject) {
if (!problemCollectionObject.hasOwnProperty(key)) continue;
let updatedproblem = advanceProblemActiveTime(problemCollectionObject[key], ADVANCE_PROBLEM_TIME_OBJ);
console.dir(updatedproblem);
}
chrome.storage.sync.set({[constants.STORAGE_PROBLEM_COLLECTION]: problemCollectionObject}, function() {
console.debug('advanced problem active time by: ' + JSON.stringify(ADVANCE_PROBLEM_TIME_OBJ));
});
}
});
}
});
chrome.storage.onChanged.addListener(function(changes, namespace) {
if (changes && changes.problem_collection_obj && changes.problem_collection_obj.newValue) {
updateBadgeText(changes.problem_collection_obj.newValue);
}
});
function updateBadgeText(problemCollectionObject) {
let badgeText = '';
if (!problemCollectionObject) badgeText = '';
let problemCountObj = getActiveCompleteProblemsCountObject(problemCollectionObject);
if (problemCountObj) {
if (problemCountObj.activeCount === 0) badgeText = '';
else if (problemCountObj.activeCount > 999) badgeText = "999+";
else badgeText = problemCountObj.activeCount.toString();
}
chrome.browserAction.setBadgeText({text: badgeText});
return badgeText;
}