Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/block.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
<script src="scripts/storage.js"></script>
<script src="scripts/common.js"></script>
<script src="scripts/block.js"></script>
<script src="scripts/restriction.js"></script>
<script src="scripts/url.js"></script>
</head>

<body>
Expand Down
3 changes: 3 additions & 0 deletions src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -119,5 +119,8 @@
<script src="scripts/chart/chart-core.js"></script>
<script src="scripts/storage.js"></script>
<script src="scripts/common.js"></script>
<script src="scripts/timeInterval.js"></script>
<script src="scripts/restriction.js"></script>
<script src="scripts/ui.js"></script>
<script src="scripts/url.js"></script>
<script src="scripts/webact.js"></script>
3 changes: 2 additions & 1 deletion src/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@
"scripts/tab.js",
"scripts/timeInterval.js",
"scripts/background.js",
"scripts/restriction.js"],
"scripts/restriction.js",
"scripts/url.js"],
"persistent": false
},
"browser_action": {
Expand Down
6 changes: 4 additions & 2 deletions src/options.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
<script src="scripts/storage.js"></script>
<script src="scripts/settings.js"></script>
<script src="scripts/restriction.js"></script>
<script src="scripts/url.js"></script>
<script src="scripts/picker/jquery-3.3.1.min.js"></script>
<script src="scripts/picker/clockpicker.min.js"></script>
</head>
Expand Down Expand Up @@ -149,7 +150,8 @@
<div id='restrictionsBlock' hidden>
<label>Access daily restrictions for websites: </label>
<div class="tooltip"><img src="/icons/information.svg" height="18" />
<span class="tooltiptext">Set the maximum time allowed on the site per day. After this time, has elapsed the site will be blocked.</span>
<span class="tooltiptext">Set the maximum time allowed on the site per day. After this time, has elapsed the site will be blocked.
Restrictions can be configured for specific paths on a site as well.</span>
</div>
<div class="margin-top-10">
<input type="text" class="label-with-list" placeholder="Enter site name..."
Expand All @@ -170,7 +172,7 @@
<label>List of sites with notifications: </label>
<div class="tooltip"><img src="/icons/information.svg" height="18" />
<span class="tooltiptext">Show notifications every time you spend a specified time interval on the
site</span>
site. Notifications can be configured for specific paths on a site as well.</span>
</div>
<div class="margin-top-10">
<input type="text" class="label-with-list" placeholder="Enter site name..." id='addNotifySiteLbl' />
Expand Down
48 changes: 26 additions & 22 deletions src/scripts/activity.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,27 @@ class Activity {
if (this.isValidPage(tab) === true) {
if (tab.id && (tab.id != 0)) {
tabs = tabs || [];
var domain = extractHostname(tab.url);
var url = new Url(tab.url);
var isDifferentUrl = false;
if (currentTab !== tab.url) {
if (!url.isMatch(currentTab)) {
isDifferentUrl = true;
}

if (this.isNewUrl(domain) && !this.isInBlackList(domain)) {
if (this.isNewUrl(url) && !this.isInBlackList(url)) {
var favicon = tab.favIconUrl;
if (favicon === undefined) {
favicon = 'chrome://favicon/' + domain;
favicon = 'chrome://favicon/' + url.host;
}
var newTab = new Tab(domain, favicon);
var newTab = new Tab(url, favicon);
tabs.push(newTab);
}

if (isDifferentUrl && !this.isInBlackList(domain)) {
this.setCurrentActiveTab(domain);
var tabUrl = this.getTab(domain);
if (isDifferentUrl && !this.isInBlackList(url)) {
this.setCurrentActiveTab(url);
var tabUrl = this.getTab(url);
if (tabUrl !== undefined)
tabUrl.incCounter();
this.addTimeInterval(domain);
this.addTimeInterval(url);
}
}
} else this.closeIntervalForCurrentTab();
Expand All @@ -41,13 +41,13 @@ class Activity {

isInBlackList(domain) {
if (setting_black_list !== undefined && setting_black_list.length > 0)
return setting_black_list.find(o => isDomainEquals(extractHostname(o), extractHostname(domain))) !== undefined;
return setting_black_list.find(o => o.isMatch(domain)) !== undefined;
else return false;
}

isLimitExceeded(domain, tab) {
if (setting_restriction_list !== undefined && setting_restriction_list.length > 0) {
var item = setting_restriction_list.find(o => isDomainEquals(extractHostname(o.domain), extractHostname(domain)));
var item = setting_restriction_list.find(o => o.url.isMatch(domain));
if (item !== undefined) {
var data = tab.days.find(x => x.date == todayLocalDate());
if (data !== undefined) {
Expand All @@ -63,7 +63,7 @@ class Activity {

wasDeferred(domain){
if (deferredRestrictionsList != undefined){
let defItem = deferredRestrictionsList.find(x => extractHostname(x.site) == extractHostname(domain));
let defItem = deferredRestrictionsList.find(x => new Url(x.site).isMatch(domain));
if (defItem != null){
let time = defItem.dateOfDeferred;
if (time + DEFERRED_TIMEOUT > new Date().getTime()){
Expand All @@ -84,19 +84,23 @@ class Activity {

isNewUrl(domain) {
if (tabs.length > 0)
return tabs.find(o => o.url === domain) === undefined;
return tabs.find(o => o.url.isMatch(domain)) === undefined;
else return true;
}

getTab(domain) {
if (tabs !== undefined)
return tabs.find(o => o.url === domain);
return tabs.find(o => o.url.isMatch(domain));
}


updateFavicon(tab) {
var domain = extractHostname(tab.url);
var currentTab = this.getTab(domain);
if (!this.isValidPage(tab)){
return;
}

var url = new Url(tab.url);
var currentTab = this.getTab(url);
if (currentTab !== null && currentTab !== undefined) {
if (tab.favIconUrl !== undefined && tab.favIconUrl !== currentTab.favicon) {
currentTab.favicon = tab.favIconUrl;
Expand All @@ -112,11 +116,11 @@ class Activity {

clearCurrentActiveTab() {
this.closeIntervalForCurrentTab();
currentTab = '';
currentTab = null;
}

addTimeInterval(domain) {
var item = timeIntervalList.find(o => o.domain === domain && o.day == todayLocalDate());
var item = timeIntervalList.find(o => o.url.isMatch(domain) && o.day == todayLocalDate());
if (item != undefined) {
if (item.day == todayLocalDate())
item.addInterval();
Expand All @@ -133,17 +137,17 @@ class Activity {
}

closeIntervalForCurrentTab() {
if (currentTab !== '' && timeIntervalList != undefined) {
var item = timeIntervalList.find(o => o.domain === currentTab && o.day == todayLocalDate());
if (currentTab && timeIntervalList != undefined) {
var item = timeIntervalList.find(o => o.url.isMatch(currentTab) && o.day == todayLocalDate());
if (item != undefined)
item.closeInterval();
}
currentTab = '';
currentTab = null;
}

isNeedNotifyView(domain, tab){
if (setting_notification_list !== undefined && setting_notification_list.length > 0) {
var item = setting_notification_list.find(o => isDomainEquals(extractHostname(o.domain), extractHostname(domain)));
var item = setting_notification_list.find(o => o.url.isMatch(domain));
if (item !== undefined) {
var today = todayLocalDate();
var data = tab.days.find(x => x.date == today);
Expand Down
53 changes: 34 additions & 19 deletions src/scripts/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ function backgroundCheck() {
if (currentWindow.focused) {
var activeTab = currentWindow.tabs.find(t => t.active === true);
if (activeTab !== undefined && activity.isValidPage(activeTab)) {
var activeUrl = extractHostname(activeTab.url);
var activeUrl = new Url(activeTab.url);
var tab = activity.getTab(activeUrl);
if (tab === undefined) {
activity.addTab(activeTab);
Expand All @@ -49,7 +49,7 @@ function backgroundCheck() {
});
} else {
if (tab !== undefined) {
if (currentTab !== tab.url) {
if (!tab.url.isMatch(currentTab)) {
activity.setCurrentActiveTab(tab.url);
}
chrome.idle.queryState(parseInt(setting_interval_inactivity), function(state) {
Expand Down Expand Up @@ -146,9 +146,9 @@ function isVideoPlayedOnPage() {
}

function checkDOM(state, activeUrl, tab, activeTab) {
if (state === 'idle' && isDomainEquals(activeUrl, "youtube.com")) {
if (state === 'idle' && activeUrl.isMatch("youtube.com")) {
trackForYT(mainTRacker, activeUrl, tab, activeTab);
} else if (state === 'idle' && isDomainEquals(activeUrl, "netflix.com")) {
} else if (state === 'idle' && activeUrl.isMatch("netflix.com")) {
trackForNetflix(mainTRacker, activeUrl, tab, activeTab);
} else activity.closeIntervalForCurrentTab();
}
Expand Down Expand Up @@ -275,13 +275,13 @@ function addListener() {
function loadTabs() {
storage.loadTabs(STORAGE_TABS, function(items) {
tabs = [];
if (items != undefined) {
for (var i = 0; i < items.length; i++) {
tabs.push(new Tab(items[i].url, items[i].favicon, items[i].days, items[i].summaryTime, items[i].counter));
}
if (isNeedDeleteTimeIntervalFromTabs)
deleteTimeIntervalFromTabs();
items = items || [];

for (var i = 0; i < items.length; i++) {
tabs.push(new Tab(items[i].url, items[i].favicon, items[i].days, items[i].summaryTime, items[i].counter));
}
if (isNeedDeleteTimeIntervalFromTabs)
deleteTimeIntervalFromTabs();
});
}

Expand All @@ -300,31 +300,46 @@ function deleteYesterdayTimeInterval() {

function loadBlackList() {
storage.getValue(STORAGE_BLACK_LIST, function(items) {
setting_black_list = items;
setting_black_list = [];
items = items || [];

for (var i = 0; i < items.length; i++) {
setting_black_list.push(new Url(url));
}
})
}

function loadTimeIntervals() {
storage.getValue(STORAGE_TIMEINTERVAL_LIST, function(items) {
timeIntervalList = [];
if (items != undefined) {
for (var i = 0; i < items.length; i++) {
timeIntervalList.push(new TimeInterval(items[i].day, items[i].domain, items[i].intervals));
}
deleteYesterdayTimeInterval();
items = items || [];

for (var i = 0; i < items.length; i++) {
timeIntervalList.push(new TimeInterval(items[i].day, items[i].url || items[i].domain, items[i].intervals));
}
deleteYesterdayTimeInterval();
});
}

function loadRestrictionList() {
storage.getValue(STORAGE_RESTRICTION_LIST, function(items) {
setting_restriction_list = items;
})
setting_restriction_list = [];
items = items || [];

for (var i = 0; i < items.length; i++) {
setting_restriction_list.push(new Restriction(items[i].url || items[i].domain, items[i].time));
}
});
}

function loadNotificationList() {
storage.getValue(STORAGE_NOTIFICATION_LIST, function(items) {
setting_notification_list = items;
setting_notification_list = [];
items = items || [];

for (var i = 0; i < items.length; i++) {
setting_notification_list.push(new Notification(items[i].url || items[i].domain, items[i].time));
}
});
}

Expand Down
13 changes: 6 additions & 7 deletions src/scripts/block.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,15 @@ var restrictionList = [];

document.addEventListener("DOMContentLoaded", function () {
var url = new URL(document.URL);
blockSiteUrl = url.searchParams.get("url");
document.getElementById("site").innerText = extractHostname(blockSiteUrl);
blockSiteUrl = new Url(url.searchParams.get("url"));
document.getElementById("site").innerText = blockSiteUrl;

storage.getValue(STORAGE_RESTRICTION_LIST, function (items) {
restrictionList = items;
restrictionList = (items || []).map(item => new Restriction(item.url || item.domain, item.time));
if (restrictionList === undefined) restrictionList = [];
var currentItem = restrictionList.find((x) =>
isDomainEquals(extractHostname(x.domain), extractHostname(blockSiteUrl))
);
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);
}
Expand All @@ -38,7 +37,7 @@ document.addEventListener("DOMContentLoaded", function () {
chrome.tabs.query(
{ currentWindow: true, active: true },
function (tab) {
chrome.tabs.update(tab.id, { url: blockSiteUrl });
chrome.tabs.update(tab.id, { url: blockSiteUrl.href });
}
);
});
Expand Down
2 changes: 1 addition & 1 deletion src/scripts/chart/chart-core.js
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,7 @@ function drawIntervalChart(data) {
})
.attr("height", function (d) {
var offset = getMinutesTo(d.interval) - getMinutesFrom(d.interval);
if (offset == 0) {
if (offset <= 0) {
var offsetSeconds = getSecondsTo(d.interval) - getSecondsFrom(d.interval);
if (offsetSeconds <= 3)
return 0;
Expand Down
39 changes: 6 additions & 33 deletions src/scripts/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,15 @@ function isEmpty(obj) {
}

function convertTimeToSummaryTime(time) {
var resultTimeValue = Number(time);
if (!isNaN(resultTimeValue)){
return resultTimeValue;
}

var timeValue = time.split(':');
var hour = timeValue[0];
var min = timeValue[1];
var resultTimeValue = 0;
resultTimeValue = 0;
if (hour > 0)
resultTimeValue = hour * 3600;
resultTimeValue += min * 60;
Expand Down Expand Up @@ -189,38 +194,6 @@ function getDateFromRange(range) {
}
}

function isDomainEquals(first, second) {
if (first === second)
return true;
else {
var resultUrl = function(url) {
if (url.indexOf('www.') > -1)
return url.split('www.')[1];
return url;
};

if (resultUrl(first) === resultUrl(second))
return true;
else return false;
}
}

function extractHostname(url) {
var hostname;

if (url.indexOf("//") > -1) {
hostname = url.split('/')[2];
}
else {
hostname = url.split('/')[0];
}

hostname = hostname.split(':')[0];
hostname = hostname.split('?')[0];

return hostname;
}

function treatAsUTC(date) {
var result = new Date(date);
result.setMinutes(result.getMinutes() - result.getTimezoneOffset());
Expand Down
Loading