Skip to content

Commit 7ac499b

Browse files
committed
Add tab class
1 parent bb4b0ff commit 7ac499b

File tree

2 files changed

+59
-0
lines changed

2 files changed

+59
-0
lines changed

src/storage/tab.ts

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import { todayLocalDate } from "../utils/common";
2+
3+
export class Tab {
4+
url: string;
5+
favicon: string;
6+
summaryTime: number = 0;
7+
counter: number = 0
8+
days: TabDay[] = [];
9+
10+
constructor(url: string, favicon: string){
11+
this.url = url;
12+
this.favicon = favicon;
13+
}
14+
15+
incSummaryTime() :void {
16+
this.summaryTime += 1;
17+
18+
const day = this.days.find(x => x.date == todayLocalDate());
19+
if (day === undefined)
20+
this.addNewDay();
21+
else day.incSummaryTime();
22+
}
23+
24+
incCounter() :void {
25+
this.counter +=1;
26+
const day = this.days.find(x => x.date == todayLocalDate());
27+
if (day === undefined)
28+
this.addNewDay();
29+
else day.incCounter()
30+
}
31+
32+
addNewDay() :void {
33+
const newTabDay = new TabDay(todayLocalDate());
34+
this.days.push(newTabDay);
35+
}
36+
}
37+
38+
export class TabDay {
39+
counter: number;
40+
date: string;
41+
summary: number;
42+
43+
constructor(date: string){
44+
this.date = date;
45+
this.counter = 1;
46+
this.summary = 1;
47+
}
48+
49+
incSummaryTime() :void {
50+
this.summary += 1;
51+
}
52+
53+
incCounter() :void {
54+
this.counter += 1;
55+
}
56+
}

src/utils/common.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export function todayLocalDate(){
2+
return new Date().toLocaleDateString('en-US');
3+
}

0 commit comments

Comments
 (0)