forked from Stigmatoz/web-activity-time-tracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtracker.ts
More file actions
36 lines (34 loc) · 1.46 KB
/
tracker.ts
File metadata and controls
36 lines (34 loc) · 1.46 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
import Browser from 'webextension-polyfill';
import { isValidPage } from './compositions/valid-page';
import { extractHostname } from './compositions/extract-hostname';
export async function initTracker(){
const window = await Browser.windows.getLastFocused({ populate: true });
if (window.focused){
const activeTab = window.tabs?.find(t => t.active === true);
if (isValidPage(activeTab)) {
var activeUrl = extractHostname(activeTab?.url);
var tab = activity.getTab(activeUrl);
if (tab === undefined) {
activity.addTab(activeTab);
}
if (activity.isInBlackList(activeUrl)) {
chrome.action.setBadgeBackgroundColor({ color: '#fdb8b8' })
chrome.action.setBadgeText({
tabId: activeTab.id,
text: 'n/a'
});
} else {
if (tab !== undefined) {
if (currentTab !== tab.url) {
activity.setCurrentActiveTab(tab.url);
}
chrome.idle.queryState(parseInt(setting_interval_inactivity), function(state) {
if (state === 'active') {
mainTRacker(activeUrl, tab, activeTab);
} else checkDOM(state, activeUrl, tab, activeTab);
});
}
}
}
} else activity.closeIntervalForCurrentTab();
}