Skip to content

Commit cb82c9e

Browse files
authored
Merge pull request Stigmatoz#53 from tschettler/fix-restrictions
Fix restrictions
2 parents 2ad18c9 + 4d62be6 commit cb82c9e

File tree

3 files changed

+27
-13
lines changed

3 files changed

+27
-13
lines changed

src/scripts/ui.js

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -213,16 +213,9 @@ class UI {
213213

214214
if (typeOfList !== undefined && typeOfList === TypeListEnum.ToDay) {
215215
if (restrictionList !== undefined && restrictionList.length > 0) {
216-
var item = restrictionList.find(x => x.url.isMatch(tab.url));
217-
if (item !== undefined) {
218-
var divLimit = this.createElement('div', ['tooltip', 'inline-block']);
219-
var limitIcon = this.createElement('img', ['margin-left-5', 'tooltip']);
220-
limitIcon.height = 15;
221-
limitIcon.src = '/icons/limit.png';
222-
var tooltip = this.createElement('span', ['tooltiptext'], "Daily limit is " + convertShortSummaryTimeToLongString(item.time));
223-
divLimit = this.appendChild(divLimit, [limitIcon, tooltip]);
224-
spanUrl.appendChild(divLimit);
225-
}
216+
this.addRestrictionIcon(tab, restrictionList, spanUrl);
217+
} else {
218+
getLimitsListFromStorage(() => this.addRestrictionIcon(tab, restrictionList, spanUrl));
226219
}
227220
}
228221

@@ -242,6 +235,19 @@ class UI {
242235
this.getTableOfSite().appendChild(div);
243236
}
244237

238+
addRestrictionIcon(tab, restrictions, spanUrl) {
239+
var item = restrictions.find(x => x.url.isMatch(tab.url));
240+
if (item !== undefined) {
241+
var divLimit = this.createElement('div', ['tooltip', 'inline-block']);
242+
var limitIcon = this.createElement('img', ['margin-left-5', 'tooltip']);
243+
limitIcon.height = 15;
244+
limitIcon.src = '/icons/limit.png';
245+
var tooltip = this.createElement('span', ['tooltiptext'], "Daily limit is " + convertShortSummaryTimeToLongString(item.time));
246+
divLimit = this.appendChild(divLimit, [limitIcon, tooltip]);
247+
spanUrl.appendChild(divLimit);
248+
}
249+
}
250+
245251
createElementsForTotalTime(summaryTime, typeOfList, parentElement) {
246252
var arr = getArrayTime(summaryTime);
247253
var isNextPartActiv = false;

src/scripts/url.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ class Url {
5151
}
5252

5353
isPathMatch(path) {
54-
var result = path === this.path || path.indexOf(this.path) === 0;
54+
var result = this.path === '' || path === this.path || path.indexOf(this.path) === 0;
5555

5656
return result;
5757
}

src/scripts/webact.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,8 +147,16 @@ window.addEventListener('click', function (e) {
147147
}
148148
});
149149

150-
function getLimitsListFromStorage() {
151-
storage.loadTabs(STORAGE_RESTRICTION_LIST, getLimitsListFromStorageCallback);
150+
function getLimitsListFromStorage(callback) {
151+
callback = callback || (() => {});
152+
if (!restrictionList) {
153+
storage.loadTabs(STORAGE_RESTRICTION_LIST, items => {
154+
getLimitsListFromStorageCallback(items);
155+
callback();
156+
});
157+
} else {
158+
callback();
159+
}
152160
}
153161

154162
function getDataFromStorage() {

0 commit comments

Comments
 (0)