Skip to content
Snippets Groups Projects
Verified Commit ab6c387b authored by Thomas Rientjes's avatar Thomas Rientjes
Browse files

Resolve #185 by allowing users to hide icon badges

parent 0f786092
No related branches found
No related tags found
No related merge requests found
...@@ -42,19 +42,22 @@ stateManager.registerInjection = function (tabIdentifier, injection) { ...@@ -42,19 +42,22 @@ stateManager.registerInjection = function (tabIdentifier, injection) {
registeredTab.injections[injectionIdentifier] = injection; registeredTab.injections[injectionIdentifier] = injection;
injectionCount = Object.keys(registeredTab.injections).length || 0; injectionCount = Object.keys(registeredTab.injections).length || 0;
if (injectionCount > 0) { if (stateManager.showIconBadge === true) {
chrome.browserAction.setBadgeText({ if (injectionCount > 0) {
tabId: tabIdentifier,
text: injectionCount.toString()
});
} else { chrome.browserAction.setBadgeText({
tabId: tabIdentifier,
text: injectionCount.toString()
});
chrome.browserAction.setBadgeText({ } else {
tabId: tabIdentifier,
text: '' chrome.browserAction.setBadgeText({
}); tabId: tabIdentifier,
text: ''
});
}
} }
if (isNaN(interceptor.amountInjected)) { if (isNaN(interceptor.amountInjected)) {
...@@ -145,16 +148,42 @@ stateManager._updateTab = function (details) { ...@@ -145,16 +148,42 @@ stateManager._updateTab = function (details) {
return; return;
} }
chrome.browserAction.setBadgeText({ if (stateManager.showIconBadge === true) {
tabId: tabIdentifier,
text: '' chrome.browserAction.setBadgeText({
}); tabId: tabIdentifier,
text: ''
});
}
if (stateManager.tabs[tabIdentifier]) { if (stateManager.tabs[tabIdentifier]) {
stateManager.tabs[tabIdentifier].injections = {}; stateManager.tabs[tabIdentifier].injections = {};
} }
}; };
stateManager._handleStorageChanged = function (changes) {
if ('showIconBadge' in changes) {
stateManager.showIconBadge = changes.showIconBadge.newValue;
if (changes.showIconBadge.newValue !== true) {
chrome.tabs.query({}, function (tabs) {
tabs.forEach(stateManager._removeIconBadgeFromTab);
});
}
}
};
stateManager._removeIconBadgeFromTab = function (tab) {
chrome.browserAction.setBadgeText({
tabId: tab.id,
text: ''
});
};
/** /**
* Initializations * Initializations
*/ */
...@@ -177,6 +206,10 @@ chrome.tabs.query({}, function (tabs) { ...@@ -177,6 +206,10 @@ chrome.tabs.query({}, function (tabs) {
tabs.forEach(stateManager._createTab); tabs.forEach(stateManager._createTab);
}); });
chrome.storage.local.get('showIconBadge', function (items) {
stateManager.showIconBadge = items.showIconBadge || true;
});
/** /**
* Event Handlers * Event Handlers
*/ */
...@@ -222,3 +255,5 @@ chrome.webRequest.onBeforeSendHeaders.addListener(function (requestDetails) { ...@@ -222,3 +255,5 @@ chrome.webRequest.onBeforeSendHeaders.addListener(function (requestDetails) {
return {requestHeaders: requestDetails.requestHeaders}; return {requestHeaders: requestDetails.requestHeaders};
}, {urls: stateManager.validHosts}, [BLOCKING_ACTION, REQUEST_HEADERS]); }, {urls: stateManager.validHosts}, [BLOCKING_ACTION, REQUEST_HEADERS]);
chrome.storage.onChanged.addListener(stateManager._handleStorageChanged);
...@@ -23,7 +23,7 @@ ...@@ -23,7 +23,7 @@
<label class="label-checkbox"> <label class="label-checkbox">
<input class="input-checkbox" data-option="showIconBadge" type="checkbox" disabled> <input class="input-checkbox" data-option="showIconBadge" type="checkbox">
<span data-i18n-content="showIconBadgeTitle"></span> <span data-i18n-content="showIconBadgeTitle"></span>
</label> </label>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment