1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-13 06:43:35 +00:00

browser action badge for current tab site count

This commit is contained in:
Kyle Spearrin
2016-09-15 23:24:45 -04:00
parent 2be753fd0a
commit 06990d524f
5 changed files with 129 additions and 15 deletions

View File

@@ -1,7 +1,42 @@
var cryptoService = new CryptoService();
var cryptoService = new CryptoService();
var tokenService = new TokenService();
var apiService = new ApiService(tokenService);
var userService = new UserService(tokenService, apiService);
var siteService = new SiteService(cryptoService, userService, apiService);
var folderService = new FolderService(cryptoService, userService, apiService);
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
});
}
});
});