forked from Stigmatoz/web-activity-time-tracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathblock.js
More file actions
43 lines (37 loc) · 1.59 KB
/
block.js
File metadata and controls
43 lines (37 loc) · 1.59 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
'use strict';
var storage = new LocalStorage();
var blockSiteUrl;
var restrictionList = [];
document.addEventListener('DOMContentLoaded', function () {
var url = new URL(document.URL);
blockSiteUrl = url.searchParams.get('url');
document.getElementById('site').innerText = extractHostname(blockSiteUrl);
storage.getValue(STORAGE_RESTRICTION_LIST, function (items) {
restrictionList = items;
if (restrictionList === undefined)
restrictionList = [];
var currentItem = restrictionList.find(x => isDomainEquals(x.domain, blockSiteUrl));
if (currentItem !== undefined){
document.getElementById('limit').innerText = convertShortSummaryTimeToString(currentItem.time);
}
});
storage.getValue(SETTINGS_BLOCK_DEFERRAL, function(item) {
var deferBtn = document.getElementById('deffererBtn');
if (item){
deferBtn.addEventListener('click', function () {
chrome.runtime.getBackgroundPage(function (bg) {
let defList = bg.deferredRestrictionsList;
if (defList == undefined)
defList = [];
defList.push({ site: blockSiteUrl, dateOfDeferred: new Date().getTime()});
bg.deferredRestrictionsList = defList;
chrome.tabs.query({ currentWindow: true, active: true }, function(tab) {
chrome.tabs.update(tab.id, { url: blockSiteUrl });
});
});
});
} else {
deferBtn.remove();
}
});
});