forked from Stigmatoz/web-activity-time-tracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathopen-page.ts
More file actions
29 lines (26 loc) · 843 Bytes
/
open-page.ts
File metadata and controls
29 lines (26 loc) · 843 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
import Browser from 'webextension-polyfill';
import { SettingsTab } from './enums';
import { getStringTab } from './extension-tabs';
export async function openPage(tab: SettingsTab, domain?: string) {
function getDomain() {
return domain != undefined && tab == SettingsTab.WebsiteStats ? `&website=${domain}` : '';
}
let tabName = getStringTab(tab);
const url = Browser.runtime.getURL(
`src/dashboard.html${tabName != '' ? `?tab=${tabName}` : ''}${getDomain()}`,
);
const currentPage = await Browser.tabs.query({
active: true,
lastFocusedWindow: true,
});
if (currentPage[0].url?.startsWith(`chrome-extension://${__APP_ID__}/src/dashboard.html`))
await Browser.tabs.update({
url: url,
active: true,
});
else
await Browser.tabs.create({
url: url,
active: true,
});
}