Skip to content

Commit 5e21134

Browse files
committed
settings part 3
1 parent 46ef9ef commit 5e21134

File tree

5 files changed

+39
-13
lines changed

5 files changed

+39
-13
lines changed

scripts/background.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,19 @@ function backgroundCheck() {
3333

3434
if (tab !== undefined) {
3535
activity.setCurrentActiveTab(tab.url);
36-
chrome.idle.queryState(setting_interval_inactivity, function (state) {
36+
chrome.idle.queryState(parseInt(setting_interval_inactivity), function (state) {
3737
if (state === 'active') {
3838
tab.incSummaryTime();
39-
if (setting_view_in_badge) {
39+
if (setting_view_in_badge === true) {
4040
chrome.browserAction.setBadgeText({
4141
tabId: activeTab.id,
4242
text: String(convertSummaryTimeToBadgeString(tab.summaryTime))
4343
});
44+
} else {
45+
chrome.browserAction.setBadgeText({
46+
tabId: activeTab.id,
47+
text: ''
48+
});
4449
}
4550
}
4651
});

scripts/common.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,3 +93,18 @@ function zeroAppend(time) {
9393
function isDateInRange(date, range){
9494
return date >= range.from && date <= range.to;
9595
}
96+
97+
function getDateFromRange(range){
98+
switch (range)
99+
{
100+
case 'days2': return 2;
101+
case 'days3': return 3;
102+
case 'days4': return 4;
103+
case 'days5': return 5;
104+
case 'days6': return 6;
105+
case 'days7': return 7;
106+
case 'month1': return 30;
107+
case 'month2': return 60;
108+
case 'month3': return 90;
109+
}
110+
}

scripts/settings.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,15 @@ document.addEventListener('DOMContentLoaded', function () {
1818
document.getElementById('clearAllData').addEventListener('click', function () {
1919
clearAllData();
2020
});
21+
document.getElementById('viewTimeInBadge').addEventListener('change', function () {
22+
storage.saveSettings(SETTINGS_VIEW_TIME_IN_BADGE, this.checked);
23+
});
24+
document.getElementById('intervalInactivity').addEventListener('change', function () {
25+
storage.saveSettings(SETTINGS_INTERVAL_INACTIVITY, this.value);
26+
});
27+
document.getElementById('rangeToDays').addEventListener('change', function () {
28+
storage.saveSettings(SETTINGS_INTERVAL_RANGE, this.value);
29+
});
2130
});
2231

2332
loadSettings();

scripts/ui.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ class UI {
157157
calendarFirst.id = 'dateFrom';
158158
calendarFirst.type = 'date';
159159
var previousDate = new Date(Date.UTC(dateNow.getFullYear(), dateNow.getMonth(), dateNow.getDate()));
160-
previousDate.setDate(previousDate.getDate() - range);
160+
previousDate.setDate(previousDate.getDate() - getDateFromRange(range));
161161
calendarFirst.valueAsDate = previousDate;
162162

163163
var calendarTwo = document.createElement('input');

scripts/webact.js

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ var today = new Date().toLocaleDateString();
1010
var setting_range_days;
1111

1212
document.addEventListener('DOMContentLoaded', function () {
13+
storage.getSettings(SETTINGS_INTERVAL_RANGE, function (item) { setting_range_days = item; });
1314
document.getElementById('btnToday').addEventListener('click', function () {
1415
currentTypeOfList = TypeListEnum.ToDay;
1516
ui.setUIForToday();
@@ -22,16 +23,15 @@ document.addEventListener('DOMContentLoaded', function () {
2223
});
2324
document.getElementById('btnByDays').addEventListener('click', function () {
2425
currentTypeOfList = TypeListEnum.ByDays;
25-
storage.getSettings(SETTINGS_INTERVAL_RANGE, function (item) { setting_range_days = item; });
2626
ui.setUIForByDays(setting_range_days);
2727
getDataFromStorageByDays();
2828
});
2929
document.getElementById('settings').addEventListener('click', function () {
3030
if (chrome.runtime.openOptionsPage) {
3131
chrome.runtime.openOptionsPage();
32-
} else {
32+
} else {
3333
window.open(chrome.runtime.getURL('options.html'));
34-
}
34+
}
3535
});
3636
});
3737

@@ -200,12 +200,10 @@ function getTabsByDays(tabs) {
200200
return item.total += a.summary;
201201
}
202202
if (item === undefined && isDateInRange(a.date, range))
203-
return listOfDays.push(
204-
{
205-
'date': a.date,
206-
'total': a.summary
207-
}
208-
);
203+
return listOfDays.push({
204+
'date': a.date,
205+
'total': a.summary
206+
});
209207
});
210208
});
211209
listOfDays = listOfDays.sort(function (a, b) {
@@ -242,7 +240,6 @@ function getTabsFromStorageByDay(day, blockName) {
242240

243241
var currentTab = getCurrentTab();
244242

245-
var tabsForChart = [];
246243
var content = document.createElement('div');
247244
content.classList.add('content-inner');
248245
content.id = blockName + '_content';

0 commit comments

Comments
 (0)