diff --git a/js/async.js b/js/async.js index d483b46e1..66241e5a8 100644 --- a/js/async.js +++ b/js/async.js @@ -19,7 +19,7 @@ Home: https://github.com/gorhill/uBlock */ -/* global chrome, µBlock */ +/* global µBlock */ /******************************************************************************/ @@ -137,26 +137,18 @@ return asyncJobManager; if ( tabId < 0 ) { return; } - var safeUpdateBagde = function(tab) { - if ( chrome.runtime.lastError ) { - return; - } - var pageStore = µBlock.pageStoreFromTabId(tab.id); + var µb = this; + var updateBadge = function() { + var pageStore = µb.pageStoreFromTabId(tabId); if ( pageStore ) { pageStore.updateBadge(); - } else { - chrome.browserAction.setIcon({ - tabId: tab.id, - path: { '19': 'img/browsericons/icon19-off.png', '38': 'img/browsericons/icon38-off.png' } - }); + return; } + µb.XAL.setIcon( + tabId, + { '19': 'img/browsericons/icon19-off.png', '38': 'img/browsericons/icon38-off.png' }, + '' + ); }; - // https://github.com/gorhill/uBlock/issues/19 - // https://github.com/gorhill/uBlock/issues/207 - // Since we may be called asynchronously, the tab id may not exist - // anymore, so this ensures it does still exist. - var unsafeUpdateBadge = function(tabId) { - chrome.tabs.get(tabId, safeUpdateBagde); - }; - this.asyncJobs.add('updateBadge-' + tabId, tabId, unsafeUpdateBadge, 250); + this.asyncJobs.add('updateBadge-' + tabId, tabId, updateBadge, 250); }; diff --git a/js/pagestore.js b/js/pagestore.js index 611b32897..1465f8431 100644 --- a/js/pagestore.js +++ b/js/pagestore.js @@ -19,7 +19,7 @@ Home: https://github.com/gorhill/uBlock */ -/* global chrome, µBlock */ +/* global µBlock */ /******************************************************************************* @@ -213,21 +213,15 @@ PageStore.prototype.recordRequest = function(type, url, reason) { PageStore.prototype.updateBadge = function() { var netFiltering = this.getNetFilteringSwitch(); - var iconPath = netFiltering ? + var iconPaths = netFiltering ? { '19': 'img/browsericons/icon19.png', '38': 'img/browsericons/icon38.png' } : { '19': 'img/browsericons/icon19-off.png', '38': 'img/browsericons/icon38-off.png' }; - chrome.browserAction.setIcon({ tabId: this.tabId, path: iconPath }); - var iconStr = ''; if ( µb.userSettings.showIconBadge && netFiltering && this.perLoadBlockedRequestCount ) { iconStr = µb.utils.formatCount(this.perLoadBlockedRequestCount); } - chrome.browserAction.setBadgeText({ tabId: this.tabId, text: iconStr }); - - if ( iconStr !== '' ) { - chrome.browserAction.setBadgeBackgroundColor({ tabId: this.tabId, color: '#666' }); - } + µb.XAL.setIcon(this.tabId, iconPaths, iconStr); }; // https://www.youtube.com/watch?v=drW8p_dTLD4