From 8a6011de8cb75dc898ca765399493eeebc67fe22 Mon Sep 17 00:00:00 2001 From: Rob Garrison Date: Sun, 22 Jul 2018 09:15:09 -0500 Subject: [PATCH] Attempt to update icon count --- background/background.js | 12 +++++++++--- background/storage.js | 3 ++- js/exclusions.js | 2 +- popup/popup-exclusions.js | 5 +++-- 4 files changed, 15 insertions(+), 7 deletions(-) diff --git a/background/background.js b/background/background.js index cb25bbfe..c505c1b5 100644 --- a/background/background.js +++ b/background/background.js @@ -381,16 +381,22 @@ function updateIcon({tab, styles}) { return; } getTabRealURL(tab) - .then(url => getStyles({matchUrl: url, asHash: true})) + .then(url => getStyles({matchUrl: url, asHash: true, omitCode: true})) .then(stylesReceived); + function getLength(styles) { + const keys = Object.keys(styles || {}); + // Using "included" because styles may not include the psuedo-section added by the + // filterStylesInternal function + return String(keys.filter(key => styles[key][0] ? styles[key][0].included : false).length); + } + function stylesReceived(styles) { const disableAll = 'disableAll' in styles ? styles.disableAll : prefs.get('disableAll'); const postfix = disableAll ? 'x' : !styles.length ? 'w' : ''; const color = prefs.get(disableAll ? 'badgeDisabled' : 'badgeNormal'); - const text = prefs.get('show-badge') && styles.length ? String(styles.length) : ''; + const text = prefs.get('show-badge') && styles.length ? getLength(styles) : ''; const iconset = ['', 'light/'][prefs.get('iconset')] || ''; - let tabIcon = tabIcons.get(tab.id); if (!tabIcon) tabIcons.set(tab.id, (tabIcon = {})); diff --git a/background/storage.js b/background/storage.js index ee49cf5c..1dd81751 100644 --- a/background/storage.js +++ b/background/storage.js @@ -315,6 +315,7 @@ function filterStylesInternal({ }); if (asHash) { if (sections.length && sections[0] !== '') { + sections.unshift({included: !isPageExcluded(matchUrl, style.exclusions)}); filtered[style.id] = sections; filtered.length++; } @@ -488,7 +489,7 @@ function getApplicableSections({ } // Show excluded style in popup if (excluded) { - return ['']; + return [{}]; } const sections = []; for (const section of style.sections) { diff --git a/js/exclusions.js b/js/exclusions.js index b8ee0efe..aec673e3 100644 --- a/js/exclusions.js +++ b/js/exclusions.js @@ -162,7 +162,7 @@ const exclusions = (() => { style.exclusions = exclusionList; style.reason = 'exclusionsUpdated'; API.saveStyle(style); - notifyAllTabs({method: 'exclusionsUpdated', style, id}); + notifyAllTabs({method: 'exclusionsUpdated', style, id, excluded: exclusionList}); }); } diff --git a/popup/popup-exclusions.js b/popup/popup-exclusions.js index e48349c4..d44aebd8 100644 --- a/popup/popup-exclusions.js +++ b/popup/popup-exclusions.js @@ -157,12 +157,13 @@ const popupExclusions = (() => { onComplete: () => (box.dataset.display = false), }); document.body.style.height = ''; + const excluded = isExcluded(tabURL, style.exclusions); if (ok) { handlePopupSave(style); entry.styleMeta = style; - entry.classList.toggle('excluded', isExcluded(tabURL, style.exclusions)); + entry.classList.toggle('excluded', excluded); } - notifyAllTabs({method: 'exclusionsUpdated', style, id: entry.styleId}); + notifyAllTabs({method: 'exclusionsUpdated', style, id: entry.styleId, affects: true, excluded}); } return Promise.resolve(); }