Microsoft has acquired GitHub. Decentraleyes has left GitHub. Welcome to its new home!

To participate, please register, or sign in with an existing GitLab.com, Bitbucket, or GitHub account.

Past contributions on GitHub? Be sure to reclaim your Comments, Issues, and Pull Requests.

Verified Commit ab6c387b authored by Thomas Rientjes's avatar Thomas Rientjes
Browse files

Resolve #185 by allowing users to hide icon badges

parent 0f786092
......@@ -42,19 +42,22 @@ stateManager.registerInjection = function (tabIdentifier, injection) {
registeredTab.injections[injectionIdentifier] = injection;
injectionCount = Object.keys(registeredTab.injections).length || 0;
if (injectionCount > 0) {
if (stateManager.showIconBadge === true) {
chrome.browserAction.setBadgeText({
tabId: tabIdentifier,
text: injectionCount.toString()
});
if (injectionCount > 0) {
} else {
chrome.browserAction.setBadgeText({
tabId: tabIdentifier,
text: injectionCount.toString()
});
chrome.browserAction.setBadgeText({
tabId: tabIdentifier,
text: ''
});
} else {
chrome.browserAction.setBadgeText({
tabId: tabIdentifier,
text: ''
});
}
}
if (isNaN(interceptor.amountInjected)) {
......@@ -145,16 +148,42 @@ stateManager._updateTab = function (details) {
return;
}
chrome.browserAction.setBadgeText({
tabId: tabIdentifier,
text: ''
});
if (stateManager.showIconBadge === true) {
chrome.browserAction.setBadgeText({
tabId: tabIdentifier,
text: ''
});
}
if (stateManager.tabs[tabIdentifier]) {
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
*/
......@@ -177,6 +206,10 @@ chrome.tabs.query({}, function (tabs) {
tabs.forEach(stateManager._createTab);
});
chrome.storage.local.get('showIconBadge', function (items) {
stateManager.showIconBadge = items.showIconBadge || true;
});
/**
* Event Handlers
*/
......@@ -222,3 +255,5 @@ chrome.webRequest.onBeforeSendHeaders.addListener(function (requestDetails) {
return {requestHeaders: requestDetails.requestHeaders};
}, {urls: stateManager.validHosts}, [BLOCKING_ACTION, REQUEST_HEADERS]);
chrome.storage.onChanged.addListener(stateManager._handleStorageChanged);
......@@ -23,7 +23,7 @@
<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>
</label>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment