forked from Stigmatoz/web-activity-time-tracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathactivity.js
More file actions
15 lines (15 loc) · 1.3 KB
/
activity.js
File metadata and controls
15 lines (15 loc) · 1.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
'use strict';class Activity{addTab(tab){if(this.isValidPage(tab)===!0){if(tab.id&&(tab.id!=0)){tabs=tabs||[];var domain=this.extractHostname(tab.url);this.setCurrentActiveTab(domain);if(this.isNewUrl(domain)){var favicon=tab.favIconUrl;if(favicon===undefined){favicon='chrome://favicon/'+domain}
var newTab=new Tab(domain,favicon);tabs.push(newTab)}}}
else this.clearCurrentActiveTab()}
isValidPage(tab){if(!tab||!tab.url||(tab.url.indexOf('http:')==-1&&tab.url.indexOf('https:')==-1)||tab.url.indexOf('chrome://')!==-1||tab.url.indexOf('chrome-extension://')!==-1)
return!1;return!0}
isNewUrl(domain){if(tabs.length>0)
return tabs.find(o=>o.url===domain)===undefined;else return!0}
getTab(domain){return tabs.find(o=>o.url===domain)}
extractHostname(url){var hostname;if(url.indexOf("//")>-1){hostname=url.split('/')[2]}
else{hostname=url.split('/')[0]}
hostname=hostname.split(':')[0];hostname=hostname.split('?')[0];return hostname}
loadDataFromStorage(){var tabs=storage.load(STORAGE_TABS)}
updateFavicon(tab){var domain=this.extractHostname(tab.url);var currentTab=this.getTab(domain);if(currentTab!==null&¤tTab!==undefined){if(tab.favIconUrl!==undefined&&tab.favIconUrl!==currentTab.favicon){currentTab.favicon=tab.favIconUrl}}}
setCurrentActiveTab(domain){currentTab=domain}
clearCurrentActiveTab(){currentTab=''}}