@@ -46,14 +46,16 @@ function getPageStats() {
4646
4747/******************************************************************************/
4848
49- var userSettingsCached = {
50- } ;
49+ function getUserSetting ( setting ) {
50+ return getHTTPSB ( ) . userSettings [ setting ] ;
51+ }
5152
52- function getUserSetting ( setting , bypassCache ) {
53- if ( bypassCache || userSettingsCached [ setting ] === undefined ) {
54- userSettingsCached [ setting ] = getHTTPSB ( ) . userSettings [ setting ] ;
55- }
56- return userSettingsCached [ setting ] ;
53+ function setUserSetting ( setting , value ) {
54+ chrome . runtime . sendMessage ( {
55+ what : 'userSettings' ,
56+ name : setting ,
57+ value : value
58+ } ) ;
5759}
5860
5961/******************************************************************************/
@@ -85,10 +87,6 @@ EntryStats.prototype.colourize = function(httpsb, scopeURL) {
8587 this . permanentColor = httpsb . getPermanentColor ( scopeURL , this . type , this . hostname ) ;
8688} ;
8789
88- EntryStats . prototype . hasTemporaryRule = function ( ) {
89- return this . temporaryColor . length > 1 && this . temporaryColor . charAt ( 1 ) === 'd' ;
90- } ;
91-
9290EntryStats . prototype . add = function ( other ) {
9391 this . count += other . count ;
9492} ;
@@ -158,22 +156,6 @@ HostnameStats.prototype.colourize = function(httpsb, scopeURL) {
158156 this . types . other . colourize ( httpsb , scopeURL ) ;
159157} ;
160158
161- HostnameStats . prototype . hasTemporaryRule = function ( ) {
162- if ( this . hasRule === undefined ) {
163- this . hasRule =
164- this . types [ '*' ] . hasTemporaryRule ( ) ||
165- this . types . main_frame . hasTemporaryRule ( ) ||
166- this . types . cookie . hasTemporaryRule ( ) ||
167- this . types . image . hasTemporaryRule ( ) ||
168- this . types . object . hasTemporaryRule ( ) ||
169- this . types . script . hasTemporaryRule ( ) ||
170- this . types . xmlhttprequest . hasTemporaryRule ( ) ||
171- this . types . sub_frame . hasTemporaryRule ( ) ||
172- this . types . other . hasTemporaryRule ( ) ;
173- }
174- return this . hasRule ;
175- } ;
176-
177159HostnameStats . prototype . add = function ( other ) {
178160 var thisTypes = this . types ;
179161 var otherTypes = other . types ;
@@ -518,15 +500,62 @@ function getNextAction(hostname, type, leaning) {
518500// the user might have collapsed/expanded one or more domains, and we don't
519501// want to lose all his hardwork.
520502
521- var explicitlyToggledDomains = { } ;
522-
523503function getCollapseState ( domain ) {
524- if ( explicitlyToggledDomains [ domain ] !== undefined ) {
525- return explicitlyToggledDomains [ domain ] ;
504+ var states = getUserSetting ( 'popupCollapseSpecificDomains' ) ;
505+ if ( states !== undefined && states [ domain ] !== undefined ) {
506+ return states [ domain ] ;
526507 }
527508 return getUserSetting ( 'popupCollapseDomains' ) ;
528509}
529510
511+ function toggleCollapseState ( element ) {
512+ var element = $ ( element ) ;
513+ if ( element . parents ( '#matHead.collapsible' ) . length > 0 ) {
514+ toggleMainCollapseState ( element ) ;
515+ } else {
516+ toggleSpecificCollapseState ( element ) ;
517+ }
518+ }
519+
520+ function toggleMainCollapseState ( element ) {
521+ var matHead = element . parents ( '#matHead.collapsible' )
522+ . toggleClass ( 'collapsed' ) ;
523+ var collapsed = matHead . hasClass ( 'collapsed' ) ;
524+ $ ( '#matList .matSection.collapsible' ) . toggleClass ( 'collapsed' , collapsed ) ;
525+ setUserSetting ( 'popupCollapseDomains' , collapsed ) ;
526+
527+ var mainCollapseState = getUserSetting ( 'popupCollapseDomains' ) ;
528+ var specificCollapseStates = getUserSetting ( 'popupCollapseSpecificDomains' ) || { } ;
529+ var domains = Object . keys ( specificCollapseStates ) ;
530+ var i = domains . length ;
531+ var domain ;
532+ while ( i -- ) {
533+ domain = domains [ i ] ;
534+ if ( specificCollapseStates [ domain ] === collapsed ) {
535+ delete specificCollapseStates [ domain ] ;
536+ }
537+ }
538+ setUserSetting ( 'popupCollapseSpecificDomains' , specificCollapseStates ) ;
539+ }
540+
541+ function toggleSpecificCollapseState ( element ) {
542+ // Remember collapse state forever, but only if it is different
543+ // from main collapse switch.
544+ var section = element . parents ( '.matSection.collapsible' )
545+ . toggleClass ( 'collapsed' ) ;
546+ var domain = section . prop ( 'domain' ) ;
547+ var collapsed = section . hasClass ( 'collapsed' ) ;
548+ var mainCollapseState = getUserSetting ( 'popupCollapseDomains' ) ;
549+ var specificCollapseStates = getUserSetting ( 'popupCollapseSpecificDomains' ) || { } ;
550+ if ( collapsed !== mainCollapseState ) {
551+ specificCollapseStates [ domain ] = collapsed ;
552+ setUserSetting ( 'popupCollapseSpecificDomains' , specificCollapseStates ) ;
553+ } else if ( specificCollapseStates [ domain ] !== undefined ) {
554+ delete specificCollapseStates [ domain ] ;
555+ setUserSetting ( 'popupCollapseSpecificDomains' , specificCollapseStates ) ;
556+ }
557+ }
558+
530559/******************************************************************************/
531560
532561// Update visual of matrix cells(s)
@@ -657,7 +686,9 @@ function formatHeader(s) {
657686/******************************************************************************/
658687
659688function renderMatrixHeaderRow ( ) {
660- var cells = $ ( '#matHead .matRow .matCell' ) ;
689+ var matHead = $ ( '#matHead.collapsible' ) ;
690+ matHead . toggleClass ( 'collapsed' , getUserSetting ( 'popupCollapseDomains' ) ) ;
691+ var cells = matHead . find ( '.matCell' ) ;
661692 $ ( cells [ 0 ] ) . prop ( { reqType : '*' , hostname : '*' } ) . addClass ( getCellClass ( '*' , '*' ) ) ;
662693 $ ( cells [ 1 ] ) . prop ( { reqType : 'cookie' , hostname : '*' } ) . addClass ( getCellClass ( '*' , 'cookie' ) ) ;
663694 $ ( cells [ 2 ] ) . prop ( { reqType : 'image' , hostname : '*' } ) . addClass ( getCellClass ( '*' , 'image' ) ) ;
@@ -686,6 +717,14 @@ function renderMatrixCellSubdomain(cell, domain, subomain) {
686717 . after ( domain ) ;
687718}
688719
720+ function renderMatrixMetaCellDomain ( cell , domain ) {
721+ $ ( cell ) . prop ( { reqType : '*' , hostname : domain } )
722+ . addClass ( getCellClass ( domain , '*' ) )
723+ . children ( 'b' )
724+ . text ( domain )
725+ . before ( '\u2217.' ) ;
726+ }
727+
689728function renderMatrixCellType ( cell , hostname , type , stats ) {
690729 cell = $ ( cell ) ;
691730 cell . prop ( { reqType : type , hostname : hostname , count : stats . count } )
@@ -726,7 +765,7 @@ function makeMatrixRowSubdomain(domain, subdomain) {
726765function makeMatrixMetaRowDomain ( domain , stats ) {
727766 var matrixRow = HTTPSBPopup . matrixRowTemplate . clone ( ) . addClass ( 'rw' ) ;
728767 var cells = $ ( '.matCell' , matrixRow ) ;
729- renderMatrixCellDomain ( cells [ 0 ] , domain ) ;
768+ renderMatrixMetaCellDomain ( cells [ 0 ] , domain ) ;
730769 renderMatrixCellTypes ( cells , domain , stats ) ;
731770 return matrixRow ;
732771}
@@ -1001,7 +1040,7 @@ function makeMatrixGroup3(group) {
10011040 . addClass ( 'matGroup g3' ) ;
10021041 $ ( '<div>' )
10031042 . addClass ( 'matSection g3Meta' )
1004- . toggleClass ( 'g3Collapsed' , ! ! getUserSetting ( 'popupHideBlacklisted' , true ) )
1043+ . toggleClass ( 'g3Collapsed' , ! ! getUserSetting ( 'popupHideBlacklisted' ) )
10051044 . appendTo ( groupDiv ) ;
10061045 makeMatrixMetaRow ( computeMatrixGroupMetaStats ( group ) , 'g3' )
10071046 . appendTo ( groupDiv ) ;
@@ -1265,52 +1304,48 @@ function initAll() {
12651304 popup . matrixCellMenu = $ ( '#cellMenu' ) . detach ( ) ;
12661305 $ ( '#persist' , popup . matrixCellMenu )
12671306 . on ( 'click' , function ( ) {
1268- handlePersistence ( $ ( this ) ) ;
1269- return false ;
1270- } )
1307+ handlePersistence ( $ ( this ) ) ;
1308+ return false ;
1309+ } )
12711310 . on ( 'mouseenter' , function ( ) {
1272- handlePersistMessage ( $ ( this ) ) ;
1273- return false ;
1274- } ) ;
1311+ handlePersistMessage ( $ ( this ) ) ;
1312+ return false ;
1313+ } ) ;
12751314 $ ( '#unpersist' , popup . matrixCellMenu )
12761315 . on ( 'click' , function ( ) {
1277- handleUnpersistence ( $ ( this ) ) ;
1278- return false ;
1279- } )
1316+ handleUnpersistence ( $ ( this ) ) ;
1317+ return false ;
1318+ } )
12801319 . on ( 'mouseenter' , function ( ) {
1281- handleUnpersistMessage ( $ ( this ) ) ;
1282- return false ;
1283- } ) ;
1320+ handleUnpersistMessage ( $ ( this ) ) ;
1321+ return false ;
1322+ } ) ;
12841323
12851324 // We reuse for all cells the one and only cell hotspots.
12861325 popup . matrixCellHotspots = $ ( '#cellHotspots' ) . detach ( ) ;
12871326 $ ( '#whitelist' , popup . matrixCellHotspots )
12881327 . on ( 'click' , function ( ) {
1289- handleWhitelistFilter ( $ ( this ) ) ;
1290- return false ;
1291- } )
1328+ handleWhitelistFilter ( $ ( this ) ) ;
1329+ return false ;
1330+ } )
12921331 . on ( 'mouseenter' , function ( ) {
1293- handleWhitelistFilterMessage ( $ ( this ) ) ;
1294- return false ;
1295- } ) ;
1332+ handleWhitelistFilterMessage ( $ ( this ) ) ;
1333+ return false ;
1334+ } ) ;
12961335 $ ( '#blacklist' , popup . matrixCellHotspots )
12971336 . on ( 'click' , function ( ) {
1298- handleBlacklistFilter ( $ ( this ) ) ;
1299- return false ;
1300- } )
1337+ handleBlacklistFilter ( $ ( this ) ) ;
1338+ return false ;
1339+ } )
13011340 . on ( 'mouseenter' , function ( ) {
13021341 handleBlacklistFilterMessage ( $ ( this ) ) ;
13031342 return false ;
1304- } ) ;
1343+ } ) ;
13051344 $ ( '#domainOnly' , popup . matrixCellHotspots )
13061345 . on ( 'click' , function ( ) {
1307- var section = $ ( this )
1308- . parents ( '.matSection.collapsible' )
1309- . toggleClass ( 'collapsed' ) ;
1310- explicitlyToggledDomains [ section . prop ( 'domain' ) ] =
1311- section . hasClass ( 'collapsed' ) ;
1312- return false ;
1313- } ) ;
1346+ toggleCollapseState ( this ) ;
1347+ return false ;
1348+ } ) ;
13141349
13151350 // to attach/detach widgets to matrix cell
13161351 $ ( 'body' )
0 commit comments