forked from Stigmatoz/web-activity-time-tracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlimit-list.ts
More file actions
55 lines (50 loc) · 1.69 KB
/
limit-list.ts
File metadata and controls
55 lines (50 loc) · 1.69 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
import { Restriction } from '../entity/restriction';
import { Tab } from '../entity/tab';
import { StorageParams } from '../storage/storage-params';
import { isDomainEquals } from '../utils/common';
import { todayLocalDate } from '../utils/date';
import { isInDeferList } from './deferList';
import { log } from '../utils/logger';
import { Settings } from './settings';
export type LimitExceed = {
IsLimitExceeded: boolean;
LimitTime: number | null;
};
export async function isLimitExceeded(url: string, tab: Tab): Promise<LimitExceed> {
const limitList = (await Settings.getInstance().getSetting(
StorageParams.RESTRICTION_LIST,
)) as Restriction[];
const array = Object.values(limitList);
const item = array?.find(x => isDomainEquals(x.domain, url));
if (item != undefined) {
const date = tab.days.find(x => x.date == todayLocalDate());
if (date != undefined) {
if (date.summary >= item.time) {
log(`Limit Exceeded: website ${url} limit ${item.time} summary time ${date.summary}`);
if (await isInDeferList(url)) {
log(`Page ${url} is in deffering list`);
return {
IsLimitExceeded: false,
LimitTime: null,
};
}
return {
IsLimitExceeded: true,
LimitTime: item.time,
};
}
}
}
return {
IsLimitExceeded: false,
LimitTime: null,
};
}
export async function isDomainInLimits(url: string): Promise<boolean> {
const limitList = (await Settings.getInstance().getSetting(
StorageParams.RESTRICTION_LIST,
)) as Restriction[];
const array = Object.values(limitList);
const item = array?.find(x => isDomainEquals(x.domain, url));
return item != undefined;
}