forked from Stigmatoz/web-activity-time-tracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathactive-tab.ts
More file actions
33 lines (27 loc) · 855 Bytes
/
active-tab.ts
File metadata and controls
33 lines (27 loc) · 855 Bytes
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
import { extractHostname } from './extract-hostname';
export class ActiveTab {
private static instance: ActiveTab;
private _activeTabUrl: string | null;
private _activeTabDomain: string | null;
constructor() {
if (ActiveTab.instance) {
throw new Error('Error - use ActiveTab.getInstance()');
}
this._activeTabUrl = null;
this._activeTabDomain = null;
}
static getInstance(): ActiveTab {
ActiveTab.instance = ActiveTab.instance || new ActiveTab();
return ActiveTab.instance;
}
public setActiveTab(value: string | null): void {
this._activeTabUrl = value;
this._activeTabDomain = value != null ? extractHostname(value) : null;
}
public getActiveTabUrl(): string | null {
return this._activeTabUrl;
}
public getActiveTabDomain(): string | null {
return this._activeTabDomain;
}
}