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
54 lines (45 loc) · 1.33 KB
/
activity.js
File metadata and controls
54 lines (45 loc) · 1.33 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
'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);
if (this.isNewUrl(domain)) {
var newTab = new Tab(domain, tab.favIconUrl);
tabs.push(newTab);
}
}
}
}
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;
}
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);
}
};