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
56 lines (50 loc) · 1.84 KB
/
block.js
File metadata and controls
56 lines (50 loc) · 1.84 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
"use strict";
var storage = new LocalStorage();
var blockSiteUrl;
var blockSiteTime;
var blockSiteCounter;
var restrictionList = [];
document.addEventListener("DOMContentLoaded", function () {
var url = new URL(document.URL);
blockSiteUrl = url.searchParams.get("url");
blockSiteTime = url.searchParams.get("summaryTime");
blockSiteCounter = url.searchParams.get("counter");
document.getElementById("site").innerText = extractHostname(blockSiteUrl);
document.getElementById("deferredTime").innerText = convertShortSummaryTimeToString(blockSiteTime);
document.getElementById("deferredCount").innerText = blockSiteCounter;
storage.getValue(STORAGE_RESTRICTION_LIST, function (items) {
restrictionList = items;
if (restrictionList === undefined) restrictionList = [];
var currentItem = restrictionList.find((x) =>
isDomainEquals(extractHostname(x.domain), extractHostname(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();
}
});
});