bitwarden-estensione-browser/src/background.js

43 lines
1.3 KiB
JavaScript
Raw Normal View History

var cryptoService = new CryptoService();
2016-09-03 06:03:13 +02:00
var tokenService = new TokenService();
2016-09-03 06:38:27 +02:00
var apiService = new ApiService(tokenService);
var userService = new UserService(tokenService, apiService);
2016-09-04 03:45:45 +02:00
var siteService = new SiteService(cryptoService, userService, apiService);
var folderService = new FolderService(cryptoService, userService, apiService);
2016-09-07 05:30:49 +02:00
var syncService = new SyncService(siteService, folderService, userService, apiService);
chrome.tabs.onUpdated.addListener(function (tabId, changeInfo, tab) {
if (!tab.url) {
return;
}
var tabDomain = tldjs.getDomain(tab.url);
if (!tabDomain) {
return;
}
var count = 0;
chrome.browserAction.setBadgeBackgroundColor({ color: '#294e5f' });
siteService.getAllDecrypted().then(function (sites) {
for (var i = 0; i < sites.length; i++) {
if (sites[i].domain && tabDomain == sites[i].domain) {
count++;
}
}
if (count > 0 && count < 9) {
chrome.browserAction.setBadgeText({
text: count.toString(),
tabId: tabId
});
}
else if (count > 0) {
chrome.browserAction.setBadgeText({
text: '9+',
tabId: tabId
});
}
});
});