Skip to content

Commit c8d3dd5

Browse files
committed
Add compositions for block list and limit list
1 parent 3076a00 commit c8d3dd5

File tree

4 files changed

+52
-1
lines changed

4 files changed

+52
-1
lines changed

src/common/utility.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,20 @@
11
export function isEmpty(obj:any): boolean {
2-
for (var prop in obj) {
2+
for (const prop in obj) {
33
if (obj.hasOwnProperty(prop))
44
return false;
55
}
66

77
return JSON.stringify(obj) === JSON.stringify({});
8+
}
9+
10+
export function convertStringTimeToSummaryTime(time:string) {
11+
const timeValue = time.split(':');
12+
const hour = Number(timeValue[0]);
13+
const min = Number(timeValue[1]);
14+
let resultTimeValue = 0;
15+
if (hour > 0)
16+
resultTimeValue = hour * 3600;
17+
resultTimeValue += min * 60;
18+
19+
return resultTimeValue;
820
}

src/compositions/block-page.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import Browser from 'webextension-polyfill';
2+
3+
export async function useBlockPage(url: string, summaryTime: number, summaryCounter: number): Promise<void>{
4+
const blockUrl = Browser.runtime.getURL("block.html") + '?url=' + url
5+
+ '&summaryTime=' + summaryTime
6+
+ '&summaryCounter=' + summaryCounter;
7+
const tab = await Browser.tabs.query({ currentWindow: true, active: true })
8+
Browser.tabs.update(tab[0].id, { url: blockUrl });
9+
}

src/compositions/limit-list.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { Restriction } from "../entity/restriction";
2+
import { Tab } from "../entity/tab";
3+
import { injecStorage } from "../storage/inject-storage";
4+
import { StorageParams } from "../storage/storage-params";
5+
import { todayLocalDate } from "../utils/common";
6+
7+
export async function isLimitExceeded(url: string, tab: Tab): Promise<boolean>{
8+
const storage = injecStorage();
9+
const limitList = await storage.getValue(StorageParams.RESTRICTION_LIST) as Restriction[];
10+
const item = limitList?.find(x => x.domain == url);
11+
if (item != undefined){
12+
const date = tab.days.find(x => x.date == todayLocalDate());
13+
if (date != undefined){
14+
return date.summary >= item.time;
15+
}
16+
}
17+
18+
return false;
19+
}

src/entity/restriction.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { convertStringTimeToSummaryTime } from "../common/utility";
2+
3+
export class Restriction {
4+
domain: string;
5+
time: number;
6+
7+
constructor(domain: string, time: string){
8+
this.domain = domain;
9+
this.time = convertStringTimeToSummaryTime(time);
10+
}
11+
}

0 commit comments

Comments
 (0)