@@ -160,42 +160,44 @@ function getActiveRulesetCount(id) {
160160
161161/**
162162 * Set the icon color correctly
163- * inactive : extension is enabled, but no rules were triggered on this page .
163+ * active : extension is enabled.
164164 * blocking: extension is in "block all HTTP requests" mode.
165- * active: extension is enabled and rewrote URLs on this page.
166165 * disabled: extension is disabled from the popup menu.
167166 */
168- var updateState = function ( ) {
169- if ( ! chrome . tabs ) {
170- return ;
167+
168+ function updateState ( ) {
169+ if ( ! chrome . tabs ) return ;
170+
171+ let iconState = 'active' ;
172+
173+ if ( ! isExtensionEnabled ) {
174+ iconState = 'disabled' ;
175+ } else if ( httpNowhereOn ) {
176+ iconState = 'blocking' ;
171177 }
178+
179+ chrome . browserAction . setIcon ( {
180+ path : {
181+ 38 : 'icons/icon-' + iconState + '-38.png'
182+ }
183+ } ) ;
184+
185+ chrome . browserAction . setTitle ( {
186+ title : 'HTTPS Everywhere' + ( iconState === 'active' ) ? '' : ' (' + iconState + ')'
187+ } ) ;
188+
172189 chrome . tabs . query ( { active : true , currentWindow : true } , function ( tabs ) {
173190 if ( ! tabs || tabs . length === 0 ) {
174191 return ;
175192 }
193+
176194 const activeCount = getActiveRulesetCount ( tabs [ 0 ] . id ) ;
177- let iconState = "inactive" ;
178- if ( ! isExtensionEnabled ) {
179- iconState = "disabled" ;
180- } else if ( httpNowhereOn ) {
181- iconState = "blocking" ;
182- } else if ( activeCount > 0 ) {
183- iconState = "active" ;
184- }
185- chrome . browserAction . setIcon ( {
186- path : {
187- "38" : "icons/icon-" + iconState + "-38.png"
188- }
189- } ) ;
190- chrome . browserAction . setTitle ( {
191- title : "HTTPS Everywhere (" + iconState + ")"
192- } ) ;
193195
194- chrome . browserAction . setBadgeBackgroundColor ( { color : " #00cc00" } ) ;
196+ chrome . browserAction . setBadgeBackgroundColor ( { color : ' #00cc00' } ) ;
195197
196198 const showBadge = activeCount > 0 && isExtensionEnabled && showCounter ;
197199
198- chrome . browserAction . setBadgeText ( { text : showBadge ? String ( activeCount ) : "" } ) ;
200+ chrome . browserAction . setBadgeText ( { text : showBadge ? String ( activeCount ) : '' } ) ;
199201 } ) ;
200202}
201203
0 commit comments