Update badge for tabs onReplaced since onUpdated doesnt always fire
This commit is contained in:
parent
c3d1d4101e
commit
6b06772f22
|
@ -31,18 +31,6 @@ function buildContextMenu() {
|
|||
contexts: ['all'],
|
||||
title: 'Copy Password'
|
||||
});
|
||||
|
||||
//chrome.contextMenus.create({
|
||||
// type: 'separator',
|
||||
// contexts: ['all']
|
||||
//});
|
||||
|
||||
//chrome.contextMenus.create({
|
||||
// type: 'normal',
|
||||
// id: 'generate-password',
|
||||
// contexts: ['all'],
|
||||
// title: 'Generate Password'
|
||||
//});
|
||||
}
|
||||
|
||||
chrome.tabs.onActivated.addListener(function (activeInfo) {
|
||||
|
@ -61,16 +49,35 @@ chrome.tabs.onActivated.addListener(function (activeInfo) {
|
|||
});
|
||||
});
|
||||
|
||||
var loadedMenuOnUpdate = false;
|
||||
chrome.tabs.onUpdated.addListener(function (tabId, changeInfo, tab) {
|
||||
loadedMenuOnUpdate = false;
|
||||
buildContextMenu();
|
||||
var loadedMenu = false;
|
||||
chrome.tabs.onReplaced.addListener(function (addedTabId, removedTabId) {
|
||||
chrome.tabs.query({ active: true, currentWindow: true }, function (tabs) {
|
||||
var tab = null;
|
||||
if (tabs.length > 0) {
|
||||
tab = tabs[0];
|
||||
}
|
||||
|
||||
if (!tab.url) {
|
||||
if (!tab) {
|
||||
return;
|
||||
}
|
||||
|
||||
var tabDomain = tldjs.getDomain(tab.url);
|
||||
loadMenuAndUpdateBadge(tab.url, tab.id, false);
|
||||
});
|
||||
});
|
||||
|
||||
chrome.tabs.onUpdated.addListener(function (tabId, changeInfo, tab) {
|
||||
buildContextMenu();
|
||||
|
||||
loadMenuAndUpdateBadge(tab.url, tabId, true);
|
||||
});
|
||||
|
||||
function loadMenuAndUpdateBadge(url, tabId, loadContextMenuOptions) {
|
||||
loadedMenu = false;
|
||||
if (!url) {
|
||||
return;
|
||||
}
|
||||
|
||||
var tabDomain = tldjs.getDomain(url);
|
||||
if (!tabDomain) {
|
||||
return;
|
||||
}
|
||||
|
@ -79,18 +86,21 @@ chrome.tabs.onUpdated.addListener(function (tabId, changeInfo, tab) {
|
|||
chrome.browserAction.setBadgeBackgroundColor({ color: '#294e5f' });
|
||||
|
||||
siteService.getAllDecrypted().then(function (sites) {
|
||||
if (loadedMenuOnUpdate) {
|
||||
if (loadedMenu) {
|
||||
return;
|
||||
}
|
||||
loadedMenuOnUpdate = true;
|
||||
loadedMenu = true;
|
||||
|
||||
sortSites(sites);
|
||||
for (var i = 0; i < sites.length; i++) {
|
||||
if (sites[i].domain && tabDomain === sites[i].domain) {
|
||||
count++;
|
||||
|
||||
if (loadContextMenuOptions) {
|
||||
loadSiteContextMenuOptions(sites[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (count > 0 && count < 9) {
|
||||
chrome.browserAction.setBadgeText({
|
||||
|
@ -112,7 +122,7 @@ chrome.tabs.onUpdated.addListener(function (tabId, changeInfo, tab) {
|
|||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
chrome.contextMenus.onClicked.addListener(function (info, tab) {
|
||||
if (info.parentMenuItemId === 'autofill' || info.parentMenuItemId === 'copy-username' ||
|
||||
|
|
Loading…
Reference in New Issue