Skip to content

Commit c1ab382

Browse files
committed
Added notifications
1 parent 6da7ba1 commit c1ab382

File tree

10 files changed

+239
-16
lines changed

10 files changed

+239
-16
lines changed

src/icons/bmc-new-btn-logo.svg

Lines changed: 29 additions & 0 deletions
Loading

src/manifest.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
"name": "Web Activity Time Tracker",
55
"short_name": "Web Time Tracker",
6-
"version": "1.3.0",
6+
"version": "1.3.1",
77
"minimum_chrome_version": "26",
88

99
"description": "Track and limit time your activity in the browser.",
@@ -23,7 +23,8 @@
2323
"idle",
2424
"chrome://favicon/*",
2525
"webNavigation",
26-
"unlimitedStorage"
26+
"unlimitedStorage",
27+
"notifications"
2728
],
2829
"optional_permissions": [
2930
"https://www.youtube.com/*"

src/options.html

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -122,14 +122,15 @@
122122
<div class="margin-top-10">
123123
<ul id='restrictionsList' class="listbox list" size="10"></ul>
124124
</div>
125-
<div class="notify warning" id='notifyForRestrictionList' hidden>
125+
<div class="notify warning notify-width-300" id='notifyForRestrictionList' hidden>
126126
The site is already in the list
127127
</div>
128128
</div>
129129
<div id='notifyBlock' hidden>
130130
<label>List of sites with notifications: </label>
131131
<div class="tooltip"><img src="/icons/information.svg" height="18" />
132-
<span class="tooltiptext">Show notifications every time you spend a specified time interval on the site</span>
132+
<span class="tooltiptext">Show notifications every time you spend a specified time interval on the
133+
site</span>
133134
</div>
134135
<div class="margin-top-10">
135136
<input type="text" class="label-with-list" placeholder="Enter site name..." id='addNotifySiteLbl' />
@@ -141,7 +142,17 @@
141142
<div class="margin-top-10">
142143
<ul id='notifyList' class="listbox list" size="10"></ul>
143144
</div>
144-
<div class="notify warning" id='notifyForNotifyList' hidden>
145+
<div class="margin-top-10">
146+
<label>You can set message for notification: </label>
147+
<div class="setting-notify-block">
148+
<img src="icons/128x128.png" class="setting-notify-img">
149+
<div class="setting-notify-message-block">
150+
<span class="setting-notify-title">Web Activity Time Tracker</span>
151+
<input type="text" class="setting-notify-message" id="notifyMessage" />
152+
</div>
153+
</div>
154+
</div>
155+
<div class="notify warning notify-width-300" id='notifyForNotifyList' hidden>
145156
The site is already in the notify list
146157
</div>
147158
</div>
@@ -165,6 +176,20 @@
165176
href="https://chrome.google.com/webstore/detail/web-activity-time-tracker/hhfnghjdeddcfegfekjeihfmbjenlomm/reviews"
166177
target="_blank">Let me know!</a></label>
167178
</div>
179+
<hr class="margin-top-20">
180+
<div class="margin-top-20">
181+
<label>You can support Web Activity Time Tracker by donating:</label>
182+
<div class="margin-top-20">
183+
<div class="inline-block">
184+
<a class="bmc-button" target="_blank" href="https://www.buymeacoffee.com/webtracker"><img
185+
src="/icons/bmc-new-btn-logo.svg" alt="Buy me a coffee"><span>Buy me a coffee</span></a>
186+
</div>
187+
<div class="inline-block">
188+
<a class="button" target="_blank" href="https://www.patreon.com/bePatron?u=19558753"
189+
data-patreon-widget-type="become-patron-button">Become a Patron!</a>
190+
</div>
191+
</div>
192+
</div>
168193
</div>
169194
</div>
170195
</div>

src/scripts/activity.js

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,6 @@ class Activity {
127127
}
128128
}
129129

130-
131130
closeIntervalForCurrentTab() {
132131
if (currentTab !== '') {
133132
var item = timeIntervalList.find(o => o.domain === currentTab && o.day == new Date().toLocaleDateString("en-US"));
@@ -136,4 +135,21 @@ class Activity {
136135
}
137136
currentTab = '';
138137
}
138+
139+
isNeedNotifyView(domain, tab){
140+
if (setting_notification_list !== undefined && setting_notification_list.length > 0) {
141+
var item = setting_notification_list.find(o => isDomainEquals(this.extractHostname(o.domain), this.extractHostname(domain)));
142+
if (item !== undefined) {
143+
var today = new Date().toLocaleDateString("en-US");
144+
var data = tab.days.find(x => x.date == today);
145+
if (data !== undefined) {
146+
var todayTimeUse = data.summary;
147+
if (todayTimeUse == item.time || todayTimeUse % item.time == 0) {
148+
return true;
149+
}
150+
}
151+
}
152+
}
153+
return false;
154+
}
139155
};

src/scripts/background.js

Lines changed: 43 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ var setting_restriction_list;
1212
var setting_interval_save;
1313
var setting_interval_inactivity;
1414
var setting_view_in_badge;
15+
var setting_notification_list;
16+
var setting_notification_message;
1517

1618
function updateSummaryTime() {
1719
setInterval(backgroundCheck, SETTINGS_INTERVAL_CHECK_DEFAULT);
@@ -61,6 +63,17 @@ function mainTRacker(activeUrl, tab, activeTab) {
6163
setBlockPageToCurrent(activeUrl);
6264
}
6365
if (!activity.isInBlackList(activeUrl)) {
66+
if (activity.isNeedNotifyView(activeUrl, tab)) {
67+
chrome.notifications.clear('watt-site-notification');
68+
chrome.notifications.create(
69+
'watt-site-notification', {
70+
type: 'basic',
71+
iconUrl: 'icons/128x128.png',
72+
title: "Web Activity Time Tracker",
73+
contextMessage: activeUrl + ' ' + convertShortSummaryTimeToString(tab.getTodayTime()),
74+
message: setting_notification_message
75+
});
76+
}
6477
tab.incSummaryTime();
6578
}
6679
if (setting_view_in_badge === true) {
@@ -137,6 +150,13 @@ function checkSettingsImEmpty() {
137150
setDefaultSettings();
138151
}
139152
});
153+
154+
storage.getValue(STORAGE_NOTIFICATION_MESSAGE, function (item) {
155+
var current = item;
156+
if (current == undefined) {
157+
storage.saveValue(STORAGE_NOTIFICATION_MESSAGE, STORAGE_NOTIFICATION_MESSAGE_DEFAULT);
158+
}
159+
});
140160
}
141161

142162
function addListener() {
@@ -168,6 +188,9 @@ function addListener() {
168188
if (key === STORAGE_RESTRICTION_LIST) {
169189
loadRestrictionList();
170190
}
191+
if (key === STORAGE_NOTIFICATION_LIST) {
192+
loadNotificationList();
193+
}
171194
if (key === SETTINGS_INTERVAL_INACTIVITY) {
172195
storage.getValue(SETTINGS_INTERVAL_INACTIVITY, function (item) { setting_interval_inactivity = item; });
173196
}
@@ -202,7 +225,7 @@ function deleteTimeIntervalFromTabs() {
202225
})
203226
}
204227

205-
function deleteYesterdayTimeInterval(){
228+
function deleteYesterdayTimeInterval() {
206229
timeIntervalList = timeIntervalList.filter(x => x.day == new Date().toLocaleDateString("en-US"));
207230
}
208231

@@ -230,16 +253,30 @@ function loadRestrictionList() {
230253
})
231254
}
232255

256+
function loadNotificationList() {
257+
storage.getValue(STORAGE_NOTIFICATION_LIST, function (items) {
258+
setting_notification_list = items;
259+
});
260+
storage.getValue(STORAGE_NOTIFICATION_MESSAGE, function (item) {
261+
setting_notification_message = item;
262+
});
263+
}
264+
233265
function loadSettings() {
234266
storage.getValue(SETTINGS_INTERVAL_INACTIVITY, function (item) { setting_interval_inactivity = item; });
235267
storage.getValue(SETTINGS_VIEW_TIME_IN_BADGE, function (item) { setting_view_in_badge = item; });
236268
}
237269

270+
function loadAddDataFromStorage(){
271+
loadTabs();
272+
loadTimeIntervals();
273+
loadBlackList();
274+
loadRestrictionList();
275+
loadNotificationList();
276+
loadSettings();
277+
}
278+
238279
addListener();
239-
loadTabs();
240-
loadTimeIntervals();
241-
loadBlackList();
242-
loadRestrictionList();
243-
loadSettings();
280+
loadAddDataFromStorage();
244281
updateSummaryTime();
245282
updateStorage();

src/scripts/common.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ var STORAGE_TABS = 'tabs';
3131
var STORAGE_BLACK_LIST = 'black_list';
3232
var STORAGE_RESTRICTION_LIST = 'restriction_list';
3333
var STORAGE_NOTIFICATION_LIST = 'notification_list';
34+
var STORAGE_NOTIFICATION_MESSAGE = 'notification_message';
3435
var STORAGE_TIMEINTERVAL_LIST = 'time_interval';
3536

3637
var SETTINGS_INTERVAL_INACTIVITY_DEFAULT = InactivityInterval.second30;
@@ -39,6 +40,7 @@ var SETTINGS_INTERVAL_SAVE_STORAGE_DEFAULT = 2000;
3940
var SETTINGS_INTERVAL_CHECK_STORAGE_DEFAULT = 3000;
4041
var SETTINGS_INTERVAL_RANGE_DEFAULT = RangeForDays.days7;
4142
var SETTINGS_VIEW_TIME_IN_BADGE_DEFAULT = true;
43+
var STORAGE_NOTIFICATION_MESSAGE_DEFAULT = 'You have spent a lot of time on this site';
4244

4345
var SETTINGS_INTERVAL_INACTIVITY = 'inactivity_interval';
4446
var SETTINGS_INTERVAL_SAVE_STORAGE = 'interval_save_in_storage';

src/scripts/settings.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ var notifyList = [];
55
var blockBtnList = ['settingsBtn', 'restrictionsBtn', 'notifyBtn', 'aboutBtn'];
66
var blockList = ['settingsBlock', 'restrictionsBlock', 'notifyBlock', 'aboutBlock'];
77

8-
98
document.addEventListener('DOMContentLoaded', function () {
109
document.getElementById('settingsBtn').addEventListener('click', function () {
1110
setBlockEvent('settingsBtn', 'settingsBlock');
@@ -47,6 +46,9 @@ document.addEventListener('DOMContentLoaded', function () {
4746
document.getElementById('grantPermission').addEventListener('click', function () {
4847
grantPermission();
4948
});
49+
document.getElementById('notifyMessage').addEventListener('change', function () {
50+
updateNotificationMessage();
51+
});
5052
$('.clockpicker').clockpicker();
5153

5254
loadSettings();
@@ -98,6 +100,9 @@ function loadSettings() {
98100
notifyList = [];
99101
viewNotificationList(items);
100102
});
103+
storage.getValue(STORAGE_NOTIFICATION_MESSAGE, function (mess) {
104+
document.getElementById('notifyMessage').value = mess;
105+
});
101106
checkPermissions();
102107
}
103108

@@ -397,4 +402,8 @@ function updateRestrictionList() {
397402

398403
function updateNotificationList() {
399404
storage.saveValue(STORAGE_NOTIFICATION_LIST, notifyList);
405+
}
406+
407+
function updateNotificationMessage() {
408+
storage.saveValue(STORAGE_NOTIFICATION_MESSAGE, document.getElementById('notifyMessage').value);
400409
}

src/scripts/tab.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@ class Tab {
3131
}
3232
}
3333

34+
getTodayTime(){
35+
var today = new Date().toLocaleDateString("en-US");
36+
return this.days.find(x => x.date == today).summary;
37+
}
38+
3439
incCounter(){
3540
this.counter +=1;
3641

src/scripts/ui.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -185,15 +185,17 @@ class UI {
185185
var spanUrl = this.createElement('span', ['span-url'], tab.url);
186186

187187
if (tab.url == currentTab) {
188+
var divForImage = document.createElement('div');
188189
div.classList.add('span-active-url');
189190
var imgCurrentDomain = document.createElement('img');
190191
imgCurrentDomain.setAttribute('src', '/icons/eye.png');
191192
imgCurrentDomain.setAttribute('height', 17);
192193
imgCurrentDomain.classList.add('margin-left-5');
193-
spanUrl.appendChild(imgCurrentDomain);
194+
divForImage.appendChild(imgCurrentDomain);
194195
var currentDomainTooltip = this.createElement('span', ['tooltiptext'], 'Current domain');
195-
spanUrl.classList.add('tooltip', 'current-url');
196-
spanUrl.appendChild(currentDomainTooltip);
196+
divForImage.classList.add('tooltip', 'current-url');
197+
divForImage.appendChild(currentDomainTooltip);
198+
spanUrl.appendChild(divForImage);
197199
}
198200

199201
if (typeOfList !== undefined && typeOfList === TypeListEnum.ToDay) {

0 commit comments

Comments
 (0)