2525
2626/******************************************************************************/
2727
28+ // OK, I keep changing my mind whether a closure should be used or not. This
29+ // will be the rule: if there are any variables directly accessed on a regular
30+ // basis, use a closure so that they are cached. Otherwise I don't think the
31+ // overhead of a closure is worth it. That's my understanding.
32+
33+ ( function ( ) {
34+
35+ /******************************************************************************/
36+
2837// ABP cosmetic filters
2938
3039var CosmeticFiltering = function ( ) {
@@ -48,7 +57,7 @@ CosmeticFiltering.prototype.retrieve = function() {
4857 what : 'retrieveABPHideSelectors' ,
4958 selectors : selectors ,
5059 locationURL : window . location . href
51- } , this . retrieveHandler ) ;
60+ } , this . retrieveHandler . bind ( this ) ) ;
5261 }
5362 this . idSelectors = null ;
5463 this . classSelectors = null ;
@@ -59,19 +68,19 @@ CosmeticFiltering.prototype.retrieveHandler = function(selectors) {
5968 return ;
6069 }
6170 var styleText = [ ] ;
62- cosmeticFiltering . reduce ( selectors . hide , cosmeticFiltering . injectedSelectors ) ;
71+ this . reduce ( selectors . hide , this . injectedSelectors ) ;
6372 if ( selectors . hide . length ) {
6473 var hideStyleText = '{{hideSelectors}} {display:none;}'
6574 . replace ( '{{hideSelectors}}' , selectors . hide . join ( ',' ) ) ;
6675 styleText . push ( hideStyleText ) ;
67- // console.log('HTTPSB> ABP cosmetic filters: injecting CSS rules:', hideStyleText);
76+ //console.log('HTTPSB> ABP cosmetic filters: injecting CSS rules:', hideStyleText);
6877 }
69- cosmeticFiltering . reduce ( selectors . donthide , cosmeticFiltering . injectedSelectors ) ;
78+ this . reduce ( selectors . donthide , this . injectedSelectors ) ;
7079 if ( selectors . donthide . length ) {
7180 var dontHideStyleText = '{{donthideSelectors}} {display:initial;}'
7281 . replace ( '{{donthideSelectors}}' , selectors . donthide . join ( ',' ) ) ;
7382 styleText . push ( dontHideStyleText ) ;
74- // console.log('HTTPSB> ABP cosmetic filters: injecting CSS rules:', donthideStyleText );
83+ //console.log('HTTPSB> ABP cosmetic filters: injecting CSS rules:', dontHideStyleText );
7584 }
7685 if ( styleText . length > 0 ) {
7786 var style = document . createElement ( 'style' ) ;
@@ -82,15 +91,22 @@ CosmeticFiltering.prototype.retrieveHandler = function(selectors) {
8291
8392CosmeticFiltering . prototype . reduce = function ( selectors , dict ) {
8493 var first = dict . httpsb === undefined ;
85- var i = selectors . length , selector ;
94+ var i = selectors . length , selector , end ;
8695 while ( i -- ) {
8796 selector = selectors [ i ] ;
8897 if ( first || ! dict [ selector ] ) {
98+ if ( end !== undefined ) {
99+ selectors . splice ( i + 1 , end - i ) ;
100+ end = undefined ;
101+ }
89102 dict [ selector ] = true ;
90- } else {
91- selectors . splice ( i , 1 ) ; // need to figure a noop rule instead if any
103+ } else if ( end === undefined ) {
104+ end = i ;
92105 }
93106 }
107+ if ( end !== undefined ) {
108+ selectors . splice ( 0 , end + 1 ) ;
109+ }
94110 dict . httpsb = true ;
95111} ;
96112
@@ -398,3 +414,7 @@ if ( /^https?:\/\/./.test(window.location.href) ) {
398414}
399415
400416/******************************************************************************/
417+
418+ } ) ( ) ;
419+
420+ /******************************************************************************/
0 commit comments