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
49 lines (43 loc) · 1.62 KB
/
block.js
File metadata and controls
49 lines (43 loc) · 1.62 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
"use strict";
var storage = new LocalStorage();
var blockSiteUrl;
var restrictionList = [];
document.addEventListener("DOMContentLoaded", function () {
var url = new URL(document.URL);
blockSiteUrl = new Url(url.searchParams.get("url"));
document.getElementById("site").innerText = blockSiteUrl;
storage.getValue(STORAGE_RESTRICTION_LIST, function (items) {
restrictionList = (items || []).map(item => new Restriction(item.url || item.domain, item.time));
if (restrictionList === undefined) restrictionList = [];
var currentItem = restrictionList.find(x => x.url.isMatch(blockSiteUrl));
if (currentItem !== undefined) {
document.getElementById("site").innerText = currentItem.url.toString();
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.href });
}
);
});
});
} else {
deferBtn.remove();
}
});
});