Skip to content

Commit cfffb95

Browse files
committed
Add feature restrictions site. part 1
1 parent 2cf3261 commit cfffb95

File tree

4 files changed

+118
-21
lines changed

4 files changed

+118
-21
lines changed

manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
"name": "Web Activity Time Tracker",
55
"short_name": "Web Activity",
6-
"version": "0.7.4",
6+
"version": "0.7.5",
77

88
"minimum_chrome_version": "26",
99

options.html

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,18 @@
1717
</div>
1818
<div id='nav' class="nav">
1919
<a id='settingsBtn' class="active">Settings</a>
20+
<a id='restrictionsBtn'>Restrictions</a>
2021
<a id='aboutBtn'>About</a>
2122
</div>
2223
<div id='block'>
23-
<div id="settingsBlock">
24+
<div id='settingsBlock'>
2425
<label>
2526
<input type="checkbox" class="filled-in" id="viewTimeInBadge" checked="checked" />
2627
<span>Display time tracker in icon</span>
2728
</label>
2829
<div class="margin-top-10">
2930
<label>Stop tracking if no activity detected for: </label>
30-
<div class="tooltip"><img src="/icons/information.svg" height="18"/>
31+
<div class="tooltip"><img src="/icons/information.svg" height="18" />
3132
<span class="tooltiptext">An activity is an action with a mouse or keyboard</span>
3233
</div>
3334
<div class="margin-top-10">
@@ -58,15 +59,15 @@
5859
</div>
5960
<div class="margin-top-10">
6061
<label>Ignored list of domain: </label>
61-
<div class="tooltip"><img src="/icons/information.svg" height="18"/>
62+
<div class="tooltip"><img src="/icons/information.svg" height="18" />
6263
<span class="tooltiptext">Activity for these domains not will tracked</span>
6364
</div>
6465
<div class="margin-top-10">
6566
<ul id='blackList' class="listbox" size="7"></ul>
6667
</div>
6768
<div class="margin-top-10">
68-
<input type="text" id='addBlackSiteLbl'/>
69-
<input type="button" value="+" id='addBlackSiteBtn'/>
69+
<input type="text" placeholder="Enter site name..." id='addBlackSiteLbl' />
70+
<input type="button" value="+" id='addBlackSiteBtn' />
7071
</div>
7172
</div>
7273
<div class="margin-top-10">
@@ -78,15 +79,31 @@
7879
</div>
7980
</div>
8081
</div>
82+
<div id='restrictionsBlock' hidden>
83+
<label>Access restrictions for websites: </label>
84+
<div class="tooltip"><img src="/icons/information.svg" height="18" />
85+
<span class="tooltiptext">Set the time you can spend on the site during the day. After this time, access to the site will be blocked.</span>
86+
</div>
87+
<div class="margin-top-10">
88+
<ul id='restrictionsList' class="listbox" size="10"></ul>
89+
</div>
90+
<div class="margin-top-10">
91+
<input type="text" placeholder="Enter site name..." id='addRestrictionSiteLbl' />
92+
<input type="time" id='addRestrictionTimeLbl' />
93+
<input type="button" value="+" id='addRestrictionSiteBtn' />
94+
</div>
95+
</div>
8196
<div id='aboutBlock' hidden>
8297
<div><label id='version'></label></div>
8398
<div class="margin-top-20">
84-
<label>If experiencing problems, having questions or suggestions, please fill out <a href="https://chrome.google.com/webstore/detail/web-activity-time-tracker/hhfnghjdeddcfegfekjeihfmbjenlomm/support"
99+
<label>If experiencing problems, having questions or suggestions, please fill out <a
100+
href="https://chrome.google.com/webstore/detail/web-activity-time-tracker/hhfnghjdeddcfegfekjeihfmbjenlomm/support"
85101
target="_blank">support
86102
form</a>.</label>
87103
</div>
88104
<div class="margin-top-20">
89-
<label>Do you enjoy using Web Activity Time Tracker? <a href="https://chrome.google.com/webstore/detail/web-activity-time-tracker/hhfnghjdeddcfegfekjeihfmbjenlomm/reviews"
105+
<label>Do you enjoy using Web Activity Time Tracker? <a
106+
href="https://chrome.google.com/webstore/detail/web-activity-time-tracker/hhfnghjdeddcfegfekjeihfmbjenlomm/reviews"
90107
target="_blank">Let me know!</a></label>
91108
</div>
92109
</div>

scripts/settings.js

Lines changed: 73 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,18 @@
11
var storage = new LocalStorage();
22
var blackList = [];
3+
var restrictionList = [];
4+
var blockBtnList = ['settingsBtn', 'restrictionsBtn', 'aboutBtn'];
5+
var blockList = ['settingsBlock', 'restrictionsBlock', 'aboutBlock'];
36

47
document.addEventListener('DOMContentLoaded', function () {
58
document.getElementById('settingsBtn').addEventListener('click', function () {
6-
document.getElementById('settingsBtn').classList.add('active');
7-
document.getElementById('aboutBtn').classList.remove('active');
8-
9-
document.getElementById('settingsBlock').hidden = false;
10-
document.getElementById('aboutBlock').hidden = true;
9+
setBlockEvent('settingsBtn', 'settingsBlock');
10+
});
11+
document.getElementById('restrictionsBtn').addEventListener('click', function () {
12+
setBlockEvent('restrictionsBtn', 'restrictionsBlock');
1113
});
1214
document.getElementById('aboutBtn').addEventListener('click', function () {
13-
document.getElementById('settingsBtn').classList.remove('active');
14-
document.getElementById('aboutBtn').classList.add('active');
15-
16-
document.getElementById('settingsBlock').hidden = true;
17-
document.getElementById('aboutBlock').hidden = false;
18-
15+
setBlockEvent('aboutBtn', 'aboutBlock');
1916
loadVersion();
2017
});
2118
document.getElementById('clearAllData').addEventListener('click', function () {
@@ -24,6 +21,9 @@ document.addEventListener('DOMContentLoaded', function () {
2421
document.getElementById('addBlackSiteBtn').addEventListener('click', function () {
2522
addNewBlackSiteClickHandler();
2623
});
24+
document.getElementById('addRestrictionSiteBtn').addEventListener('click', function () {
25+
addNewRestrictionSiteClickHandler();
26+
});
2727
document.getElementById('viewTimeInBadge').addEventListener('change', function () {
2828
storage.saveSettings(SETTINGS_VIEW_TIME_IN_BADGE, this.checked);
2929
});
@@ -37,6 +37,21 @@ document.addEventListener('DOMContentLoaded', function () {
3737

3838
loadSettings();
3939

40+
function setBlockEvent(btnName, blockName) {
41+
blockBtnList.forEach(element => {
42+
if (element === btnName){
43+
document.getElementById(btnName).classList.add('active');
44+
}
45+
else document.getElementById(element).classList.remove('active');
46+
});
47+
48+
blockList.forEach(element => {
49+
if (element === blockName){
50+
document.getElementById(blockName).hidden = false;
51+
} else document.getElementById(element).hidden = true;
52+
});
53+
}
54+
4055
function loadSettings() {
4156
storage.getSettings(SETTINGS_INTERVAL_INACTIVITY, function (item) {
4257
document.getElementById('intervalInactivity').value = item;
@@ -56,7 +71,7 @@ function loadSettings() {
5671
});
5772
}
5873

59-
function loadVersion(){
74+
function loadVersion() {
6075
var version = chrome.runtime.getManifest().version;
6176
document.getElementById('version').innerText = 'v' + version;
6277
}
@@ -92,6 +107,18 @@ function addNewBlackSiteClickHandler() {
92107
updateBlackList();
93108
}
94109

110+
function addNewRestrictionSiteClickHandler(){
111+
var newRestrictionSite = document.getElementById('addRestrictionSiteLbl').value;
112+
if (newRestrictionSite !== '') {
113+
addDomainToRestrictionListBox(newRestrictionSite);
114+
if (restrictionList === undefined)
115+
restrictionList = [];
116+
restrictionList.push(newRestrictionSite);
117+
document.getElementById('addRestrictionSiteLbl').value = '';
118+
}
119+
updateRestrictionList();
120+
}
121+
95122
function addDomainToListBox(domain) {
96123
var li = document.createElement('li');
97124
li.innerText = domain;
@@ -104,13 +131,47 @@ function addDomainToListBox(domain) {
104131
document.getElementById('blackList').appendChild(li).appendChild(del);
105132
}
106133

134+
function addDomainToRestrictionListBox(domain) {
135+
var li = document.createElement('li');
136+
li.innerText = domain;
137+
var edit = document.createElement('img');
138+
edit.height = 12;
139+
edit.src = '/icons/delete.png';
140+
edit.addEventListener('click', function (e) {
141+
editRestrictionSite(e);
142+
});
143+
var del = document.createElement('img');
144+
del.height = 12;
145+
del.src = '/icons/delete.png';
146+
del.addEventListener('click', function (e) {
147+
deleteRestrictionSite(e);
148+
});
149+
var li = document.getElementById('restrictionsList').appendChild(li);
150+
li.appendChild(del);
151+
li.appendChild(edit);
152+
}
153+
107154
function deleteBlackSite(e) {
108155
var targetElement = e.path[1];
109156
blackList.splice(blackList.indexOf(targetElement.innerText), 1);
110157
document.getElementById('blackList').removeChild(targetElement);
111158
updateBlackList();
112159
}
113160

161+
function deleteRestrictionSite(e) {
162+
var targetElement = e.path[1];
163+
restrictionList.splice(restrictionList.indexOf(targetElement.innerText), 1);
164+
document.getElementById('restrictionsList').removeChild(targetElement);
165+
updateRestrictionList();
166+
}
167+
168+
function editRestrictionSite(e){
169+
170+
}
171+
114172
function updateBlackList() {
115173
storage.saveSettings(STORAGE_BLACK_LIST, blackList);
174+
}
175+
176+
function updateRestrictionList() {
116177
}

style/settings.css

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,4 +277,23 @@ input[type="button"]:hover {
277277
padding: 0 5px !important;
278278
min-width: 20px !important;
279279
width: 28px !important;
280-
}
280+
}
281+
282+
#addRestrictionSiteLbl{
283+
width: 233px;
284+
height: 15px;
285+
padding: 3px;
286+
}
287+
288+
#addRestrictionSiteBtn{
289+
height: 24px !important;
290+
line-height: 20px !important;
291+
padding: 0 5px !important;
292+
min-width: 20px !important;
293+
width: 28px !important;
294+
}
295+
296+
#restrictionsList{
297+
width: 430px;
298+
height: 170px;
299+
}

0 commit comments

Comments
 (0)