Skip to content

Commit 4376c39

Browse files
committed
add percentage of time
1 parent 0851d08 commit 4376c39

File tree

3 files changed

+23
-5
lines changed

3 files changed

+23
-5
lines changed

scripts/activity.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ class Activity {
99
if (this.isNewUrl(domain)) {
1010
var favicon = tab.favIconUrl;
1111
if (favicon === undefined){
12-
favicon = 'chrome://favicon/' + tab.url;
12+
favicon = 'chrome://favicon/' + domain;
1313
}
1414
var newTab = new Tab(domain, favicon);
1515
tabs.push(newTab);

scripts/webact.js

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
'use strict';
22

33
var storage = new LocalStorage();
4+
var totalTime;
45

56
getDataFromStorage();
67

@@ -14,6 +15,9 @@ function getTabsFromStorage(tabs) {
1415
tabs = tabs.sort(function (a, b) {
1516
return b.summaryTime - a.summaryTime;
1617
});
18+
19+
totalTime = setTotalTime(tabs);
20+
1721
for (var i = 0; i < tabs.length; i++) {
1822
var div = document.createElement('div');
1923
div.classList.add('inline-flex');
@@ -27,21 +31,30 @@ function getTabsFromStorage(tabs) {
2731
spanUrl.classList.add('span-url');
2832
spanUrl.innerText = tabs[i].url;
2933

34+
var spanPercentage = document.createElement('span');
35+
spanPercentage.classList.add('span-percentage');
36+
spanPercentage.innerText = setPercentage(tabs[i].summaryTime);
37+
3038
var spanTime = document.createElement('span');
3139
spanTime.classList.add('span-time');
3240
spanTime.innerText = convertSummaryTimeToString(tabs[i].summaryTime);
3341

3442
div.appendChild(img);
3543
div.appendChild(spanUrl);
44+
div.appendChild(spanPercentage);
3645
div.appendChild(spanTime);
3746
table.appendChild(div);
3847
}
39-
40-
setTotalTime(tabs);
4148
}
4249

4350
function setTotalTime(tabs) {
4451
var summaryTimeList = tabs.map(function (a) { return a.summaryTime; });
4552
var total = summaryTimeList.reduce(function (a, b) { return a + b; })
4653
document.getElementById('totalTime').innerText = convertSummaryTimeToString(total);
54+
55+
return total;
56+
}
57+
58+
function setPercentage(time){
59+
return ((time / totalTime) * 100).toFixed(2) + '%';
4760
}

style/webact.css

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,19 @@ body {
2020
}
2121

2222
.span-total{
23-
width: 220px;
23+
width: 260px;
2424
text-decoration: none;
2525
color: rgb(0, 0, 0);
2626
font-size: 12px;
2727
font-weight: 600;
2828
cursor: pointer;
2929
}
3030

31+
.span-percentage{
32+
color: rgb(78, 78, 78);
33+
font-size: 11px;
34+
}
35+
3136
.span-time{
3237
margin-left: 10px;
3338
width: 70px;
@@ -40,6 +45,6 @@ body {
4045

4146
hr {
4247
border: none;
43-
background-color: rgb(187, 187, 187);
48+
background-color: rgb(223, 222, 222);
4449
height: 2px;
4550
}

0 commit comments

Comments
 (0)