-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbackground.js
76 lines (64 loc) · 2.1 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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
// --------Dashboard Functions---------//
function currentTab (){
// chrome.tabs.query({currentWindow: true, active: true}, function(tabs){
// console.log(tabs[0].url);
// });
chrome.browserAction.onClicked.addListener(function(e){
console.log(e.url);
//give you the url of the tab on which you clicked the extension
})
}
//-----------------------------Visited sites-----------//
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-45267314-2']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = 'https://ssl.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
function clearStats() {
if (config.clearStatsInterval < 3600) {
config.nextTimeToClear = 0;
return;
}
if (!config.nextTimeToClear) {
var d = new Date();
d.setTime(d.getTime() + config.clearStatsInterval * 1000);
d.setMinutes(0);
d.setSeconds(0);
if (config.clearStatsInterval > 3600) {
d.setHours(0);
}
config.nextTimeToClear = d.getTime();
}
var now = new Date();
if (now.getTime() > config.nextTimeToClear) {
sites.clear();
var nextTimeToClear = new Date(nextTimeToClear + config.clearStatsInterval * 1000);
config.nextTimeToClear = nextTimeToClear.getTime();
return;
}
}
var config = new Config();
var sites = new Sites(config);
var tracker = new Tracker(config, sites);
/* Listen for requests which come from the user through the popup. */
chrome.extension.onRequest.addListener(
function(request, sender, sendResponse) {
if (request.action == "clearStats") {
sites.clear();
sendResponse({});
} else if (request.action == "addIgnoredSite") {
config.addIgnoredSite(request.site);
sendResponse({});
} else {
console.log("Invalid action given: " + request.action);
}
});
chrome.alarms.create("clearStats", {periodInMinutes: 2});
chrome.alarms.onAlarm.addListener(function(alarm) {
if (alarm.name == "clearStats") {
clearStats(config);
}
});