Skip to content

Commit c7d387b

Browse files
committed
add view favicon for url
1 parent 9c1c6a8 commit c7d387b

File tree

5 files changed

+41
-26
lines changed

5 files changed

+41
-26
lines changed

manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
"storage"
2222
],
2323
"background": {
24-
"scripts": ["scripts/background.js", "scripts/webTimer.js", "scripts/tab.js"],
24+
"scripts": ["scripts/webTimer.js", "scripts/tab.js", "scripts/background.js"],
2525
"persistent": false
2626
},
2727
"browser_action": {

scripts/background.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
1+
var timer = new WebTimer();
2+
13
window.onload = function () {
2-
window.timer = new WebTimer();
34
chrome.tabs.onActivated.addListener(function (info) {
45
chrome.tabs.get(info.tabId, function (tab) {
5-
window.timer.addTab(tab);
6+
timer.addTab(tab);
67
});
78
});
9+
chrome.tabs.onUpdated.addListener(function (tabId, changeInfo, tab) {
10+
timer.addTab(tab);
11+
});
812
};

scripts/webTimer.js

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -6,42 +6,35 @@ WebTimer.prototype = {
66

77
addTab: function (tab) {
88
if (this.isValidPage(tab) === true) {
9-
if (tab.id && (tab.id != 0)) {
9+
if (tab.id && (tab.id != 0)) {
1010
this.tabs = this.tabs || [];
11-
var domain = this.extractRootDomain(tab.url);
12-
if (!this.tabs.includes(domain)){
13-
this.tabs.push(domain);
11+
var domain = this.extractHostname(tab.url);
12+
if (this.isNewUrl(domain)) {
13+
var newTab = new Tab(domain, tab.favIconUrl);
14+
this.tabs.push(newTab);
1415
}
1516
this.startTimeTracker(tab);
1617
this.currentTab = domain;
1718
}
1819
}
1920
},
2021

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;
22+
isNewUrl: function (domain) {
23+
if (this.tabs.length > 0)
24+
return this.tabs.find(o => o.url === domain) === undefined;
25+
else return true;
3326
},
3427

35-
extractHostname: function(url) {
28+
extractHostname: function (url) {
3629
var hostname;
37-
30+
3831
if (url.indexOf("//") > -1) {
3932
hostname = url.split('/')[2];
4033
}
4134
else {
4235
hostname = url.split('/')[0];
4336
}
44-
37+
4538
hostname = hostname.split(':')[0];
4639
hostname = hostname.split('?')[0];
4740

@@ -56,7 +49,7 @@ WebTimer.prototype = {
5649
return true;
5750
},
5851

59-
startTimeTracker: function(tab){
52+
startTimeTracker: function (tab) {
6053
var tab = new Tab(tab.url, tab.favIconUrl);
6154
}
6255
};

scripts/webact.js

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,19 @@ window.onload = function () {
22
var table = document.getElementById('resultTable');
33
var tabs = chrome.extension.getBackgroundPage().timer.tabs;
44
for (var i = 0; i < tabs.length; i++) {
5-
var p = document.createElement('p');
6-
p.innerText = tabs[i];
7-
table.appendChild(p);
5+
var div = document.createElement('div');
6+
div.classList.add('inline-flex');
7+
8+
var img = document.createElement('img');
9+
img.setAttribute('height', 15);
10+
img.setAttribute('src', tabs[i].favicon);
11+
12+
var span = document.createElement('span');
13+
span.innerText = tabs[i].url;
14+
span.classList.add('margin-left-5');
15+
16+
div.appendChild(img);
17+
div.appendChild(span);
18+
table.appendChild(div);
819
}
920
};

style/webact.css

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
.inline-flex{
2+
display: inline-flex;
3+
}
4+
5+
.margin-left-5{
6+
margin-left: 5px;
7+
}

0 commit comments

Comments
 (0)