Skip to content

Commit 9c1c6a8

Browse files
committed
add new entity
1 parent 141efa2 commit 9c1c6a8

File tree

4 files changed

+78
-60
lines changed

4 files changed

+78
-60
lines changed

manifest.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,11 @@
1717
},
1818
"permissions": [
1919
"tabs",
20-
"activeTab"
20+
"activeTab",
21+
"storage"
2122
],
2223
"background": {
23-
"scripts": ["scripts/background.js"],
24+
"scripts": ["scripts/background.js", "scripts/webTimer.js", "scripts/tab.js"],
2425
"persistent": false
2526
},
2627
"browser_action": {

scripts/background.js

Lines changed: 0 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -5,62 +5,4 @@ window.onload = function () {
55
window.timer.addTab(tab);
66
});
77
});
8-
};
9-
10-
var WebTimer = function () { };
11-
12-
WebTimer.prototype = {
13-
tabs: [],
14-
activeTab: {},
15-
16-
addTab: function (tab) {
17-
if (this.isValidPage(tab) === true) {
18-
if (tab.id && (tab.id != 0)) {
19-
this.tabs = this.tabs || [];
20-
var domain = this.extractRootDomain(tab.url);
21-
if (!this.tabs.includes(domain)){
22-
this.tabs.push(domain);
23-
}
24-
this.activeTab = domain;
25-
}
26-
}
27-
},
28-
29-
extractRootDomain: function (url) {
30-
var domain = this.extractHostname(url),
31-
splitArr = domain.split('.'),
32-
arrLen = splitArr.length;
33-
34-
if (arrLen > 2) {
35-
domain = splitArr[arrLen - 2] + '.' + splitArr[arrLen - 1];
36-
if (splitArr[arrLen - 2].length == 2 && splitArr[arrLen - 1].length == 2) {
37-
domain = splitArr[arrLen - 3] + '.' + domain;
38-
}
39-
}
40-
return domain;
41-
},
42-
43-
extractHostname: function(url) {
44-
var hostname;
45-
46-
if (url.indexOf("//") > -1) {
47-
hostname = url.split('/')[2];
48-
}
49-
else {
50-
hostname = url.split('/')[0];
51-
}
52-
53-
hostname = hostname.split(':')[0];
54-
hostname = hostname.split('?')[0];
55-
56-
return hostname;
57-
},
58-
59-
isValidPage: function (tab) {
60-
if (!tab || !tab.url || (tab.url.indexOf('http:') == -1 && tab.url.indexOf('https:') == -1)
61-
|| tab.url.indexOf('chrome://') !== -1
62-
|| tab.url.indexOf('chrome-extension://') !== -1)
63-
return false;
64-
return true;
65-
}
668
};

scripts/tab.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
var Tab = function (domain, favicon) {
2+
this.url = domain;
3+
this.startTime = Date.now;
4+
this.favicon = favicon;
5+
};
6+
7+
Tab.prototype = {
8+
url: {},
9+
startTime: {},
10+
summaryTime: {},
11+
favicon: {},
12+
percentage: {}
13+
};

scripts/webTimer.js

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
var WebTimer = function () { };
2+
3+
WebTimer.prototype = {
4+
tabs: [],
5+
currentTab: {},
6+
7+
addTab: function (tab) {
8+
if (this.isValidPage(tab) === true) {
9+
if (tab.id && (tab.id != 0)) {
10+
this.tabs = this.tabs || [];
11+
var domain = this.extractRootDomain(tab.url);
12+
if (!this.tabs.includes(domain)){
13+
this.tabs.push(domain);
14+
}
15+
this.startTimeTracker(tab);
16+
this.currentTab = domain;
17+
}
18+
}
19+
},
20+
21+
extractRootDomain: function (url) {
22+
var domain = this.extractHostname(url),
23+
splitArr = domain.split('.'),
24+
arrLen = splitArr.length;
25+
26+
if (arrLen > 2) {
27+
domain = splitArr[arrLen - 2] + '.' + splitArr[arrLen - 1];
28+
if (splitArr[arrLen - 2].length == 2 && splitArr[arrLen - 1].length == 2) {
29+
domain = splitArr[arrLen - 3] + '.' + domain;
30+
}
31+
}
32+
return domain;
33+
},
34+
35+
extractHostname: function(url) {
36+
var hostname;
37+
38+
if (url.indexOf("//") > -1) {
39+
hostname = url.split('/')[2];
40+
}
41+
else {
42+
hostname = url.split('/')[0];
43+
}
44+
45+
hostname = hostname.split(':')[0];
46+
hostname = hostname.split('?')[0];
47+
48+
return hostname;
49+
},
50+
51+
isValidPage: function (tab) {
52+
if (!tab || !tab.url || (tab.url.indexOf('http:') == -1 && tab.url.indexOf('https:') == -1)
53+
|| tab.url.indexOf('chrome://') !== -1
54+
|| tab.url.indexOf('chrome-extension://') !== -1)
55+
return false;
56+
return true;
57+
},
58+
59+
startTimeTracker: function(tab){
60+
var tab = new Tab(tab.url, tab.favIconUrl);
61+
}
62+
};

0 commit comments

Comments
 (0)