forked from Stigmatoz/web-activity-time-tracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathactivity.js
More file actions
84 lines (71 loc) · 2.31 KB
/
activity.js
File metadata and controls
84 lines (71 loc) · 2.31 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
'use strict';
class Activity {
addTab(tab) {
if (this.isValidPage(tab) === true) {
if (tab.id && (tab.id != 0)) {
tabs = tabs || [];
var domain = this.extractHostname(tab.url);
this.setCurrentActiveTab(domain);
if (this.isNewUrl(domain) && !this.isInBlackList(domain)) {
var favicon = tab.favIconUrl;
if (favicon === undefined){
favicon = 'chrome://favicon/' + domain;
}
var newTab = new Tab(domain, favicon);
tabs.push(newTab);
}
}
}
else this.clearCurrentActiveTab();
}
isValidPage(tab) {
if (!tab || !tab.url || (tab.url.indexOf('http:') == -1 && tab.url.indexOf('https:') == -1)
|| tab.url.indexOf('chrome://') !== -1
|| tab.url.indexOf('chrome-extension://') !== -1)
return false;
return true;
}
isInBlackList(domain){
if (setting_black_list !== undefined && setting_black_list.length > 0)
return setting_black_list.find(o => o === domain) !== undefined;
else return false;
}
isNewUrl(domain) {
if (tabs.length > 0)
return tabs.find(o => o.url === domain) === undefined;
else return true;
}
getTab(domain) {
return tabs.find(o => o.url === domain);
}
extractHostname(url) {
var hostname;
if (url.indexOf("//") > -1) {
hostname = url.split('/')[2];
}
else {
hostname = url.split('/')[0];
}
hostname = hostname.split(':')[0];
hostname = hostname.split('?')[0];
return hostname;
}
loadDataFromStorage(){
var tabs = storage.load(STORAGE_TABS);
}
updateFavicon(tab){
var domain = this.extractHostname(tab.url);
var currentTab = this.getTab(domain);
if (currentTab !== null && currentTab !== undefined){
if (tab.favIconUrl !== undefined && tab.favIconUrl !== currentTab.favicon){
currentTab.favicon = tab.favIconUrl;
}
}
}
setCurrentActiveTab(domain){
currentTab = domain;
}
clearCurrentActiveTab(){
currentTab = '';
}
};