forked from Stigmatoz/web-activity-time-tracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsettings.js
More file actions
77 lines (69 loc) · 3.07 KB
/
settings.js
File metadata and controls
77 lines (69 loc) · 3.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
var storage = new LocalStorage();
document.addEventListener('DOMContentLoaded', function () {
document.getElementById('settingsBtn').addEventListener('click', function () {
document.getElementById('settingsBtn').classList.add('active');
document.getElementById('aboutBtn').classList.remove('active');
document.getElementById('settingsBlock').hidden = false;
document.getElementById('aboutBlock').hidden = true;
});
document.getElementById('aboutBtn').addEventListener('click', function () {
document.getElementById('settingsBtn').classList.remove('active');
document.getElementById('aboutBtn').classList.add('active');
document.getElementById('settingsBlock').hidden = true;
document.getElementById('aboutBlock').hidden = false;
});
document.getElementById('clearAllData').addEventListener('click', function () {
clearAllData();
});
document.getElementById('addBlackSiteBtn').addEventListener('click', function () {
addNewBlackSite();
});
document.getElementById('viewTimeInBadge').addEventListener('change', function () {
storage.saveSettings(SETTINGS_VIEW_TIME_IN_BADGE, this.checked);
});
document.getElementById('intervalInactivity').addEventListener('change', function () {
storage.saveSettings(SETTINGS_INTERVAL_INACTIVITY, this.value);
});
document.getElementById('rangeToDays').addEventListener('change', function () {
storage.saveSettings(SETTINGS_INTERVAL_RANGE, this.value);
});
});
loadSettings();
function loadSettings() {
storage.getSettings(SETTINGS_INTERVAL_INACTIVITY, function (item) {
document.getElementById('intervalInactivity').value = item;
});
storage.getSettings(SETTINGS_INTERVAL_RANGE, function (item) {
document.getElementById('rangeToDays').value = item;
});
storage.getSettings(SETTINGS_VIEW_TIME_IN_BADGE, function (item) {
document.getElementById('viewTimeInBadge').setAttribute('checked', item);
});
storage.getMemoryUse(STORAGE_TABS, function (integer) {
document.getElementById('memoryUse').innerHTML = (integer / 1024).toFixed(2) + 'Kb';
})
}
function clearAllData() {
var tabs = [];
chrome.extension.getBackgroundPage().tabs = tabs;
storage.saveTabs(tabs, viewNotify);
}
function viewNotify() {
document.getElementById('notify').hidden = false;
setTimeout(function () { document.getElementById('notify').hidden = true; }, 3000);
}
function addNewBlackSite() {
var newBlackSite = document.getElementById('addBlackSiteLbl').value;
if (newBlackSite !== '') {
var count = document.getElementById('blackList').getElementsByTagName('li').length;
var li = document.createElement('li');
li.innerHTML = newBlackSite;
li.value = count++;
var del = document.createElement('img');
del.height = 12;
del.src = '/icons/delete.png';
del.value = count++;
document.getElementById('blackList').appendChild(li).appendChild(del);
document.getElementById('addBlackSiteLbl').value = '';
}
}