2525
2626/******************************************************************************/
2727
28+ var selectedRemoteBlacklistsHash = '' ;
29+
30+ /******************************************************************************/
31+
2832function gethttpsb ( ) {
2933 return chrome . extension . getBackgroundPage ( ) . HTTPSB ;
3034}
3135
3236/******************************************************************************/
3337
38+ function renderNumber ( value ) {
39+ // TODO: localization
40+ if ( + value > 1000 ) {
41+ value = value . toString ( ) ;
42+ var i = value . length - 3 ;
43+ while ( i > 0 ) {
44+ value = value . slice ( 0 , i ) + ',' + value . slice ( i ) ;
45+ i -= 3 ;
46+ }
47+ }
48+ return value ;
49+ }
50+
51+ /******************************************************************************/
52+
3453function changeUserSettings ( name , value ) {
3554 chrome . runtime . sendMessage ( {
3655 what : 'userSettings' ,
@@ -58,6 +77,98 @@ function onChangeValueHandler(elem, setting, min, max) {
5877
5978/******************************************************************************/
6079
80+ function renderBlacklistDetails ( ) {
81+ // empty list first
82+ $ ( '#remoteBlacklists .remoteBlacklistDetails' ) . remove ( ) ;
83+
84+ // then fill it
85+ var httpsb = gethttpsb ( ) ;
86+
87+ $ ( '#blacklistReadonlyCount' ) . text ( renderNumber ( httpsb . blacklistReadonlyCount ) ) ;
88+
89+ var blacklists = httpsb . remoteBlacklists ;
90+ var ul = $ ( '#remoteBlacklists' ) ;
91+ var keys = Object . keys ( blacklists ) ;
92+ var i = keys . length ;
93+ var blacklist ;
94+ var liTemplate = $ ( '#remoteBlacklistsTemplate .remoteBlacklistDetails' ) . first ( ) ;
95+ var li , child ;
96+ while ( i -- ) {
97+ blacklist = blacklists [ keys [ i ] ] ;
98+ li = liTemplate . clone ( ) ;
99+ child = $ ( 'input' , li ) ;
100+ child . prop ( 'checked' , ! blacklist . off ) ;
101+ child = $ ( 'a' , li ) ;
102+ child . attr ( 'href' , keys [ i ] ) ;
103+ child . text ( keys [ i ] ) ;
104+ child = $ ( 'span' , li ) ;
105+ child . text ( ! isNaN ( + blacklist . entryCount ) ? renderNumber ( blacklist . entryCount ) : '?' ) ;
106+ ul . prepend ( li ) ;
107+ }
108+ selectedRemoteBlacklistsHash = getSelectedRemoteBlacklistsHash ( ) ;
109+ }
110+
111+ /******************************************************************************/
112+
113+ function reloadRemoteBlacklistsHandler ( ) {
114+ var newHash = getSelectedRemoteBlacklistsHash ( ) ;
115+ if ( newHash === selectedRemoteBlacklistsHash ) {
116+ return ;
117+ }
118+ // Reload blacklists
119+ var switches = [ ] ;
120+ var lis = $ ( '#remoteBlacklists .remoteBlacklistDetails' ) ;
121+ var i = lis . length ;
122+ while ( i -- ) {
123+ switches . push ( {
124+ location : $ ( lis [ i ] ) . children ( 'a' ) . attr ( 'href' ) ,
125+ off : $ ( lis [ i ] ) . children ( 'input' ) . prop ( 'checked' ) === false
126+ } ) ;
127+ }
128+ chrome . runtime . sendMessage ( {
129+ what : 'reloadPresetBlacklists' ,
130+ switches : switches
131+ } ) ;
132+ $ ( '#reloadRemoteBlacklists' ) . attr ( 'disabled' , true ) ;
133+ }
134+
135+ /******************************************************************************/
136+
137+ // Create a hash so that we know whether the selection of preset blacklists
138+ // has changed.
139+
140+ function getSelectedRemoteBlacklistsHash ( ) {
141+ var hash = '' ;
142+ var inputs = $ ( '#remoteBlacklists .remoteBlacklistDetails > input' ) ;
143+ var i = inputs . length ;
144+ while ( i -- ) {
145+ hash += $ ( inputs [ i ] ) . prop ( 'checked' ) . toString ( ) ;
146+ }
147+ return hash ;
148+ }
149+
150+ // This is to give a visual hint that the selection of preset blacklists has
151+ // changed and thus user needs to explicitly click the reload button.
152+
153+ function remoteBlacklistDetailsChangeHandler ( ) {
154+ $ ( '#reloadRemoteBlacklists' ) . attr ( 'disabled' , getSelectedRemoteBlacklistsHash ( ) === selectedRemoteBlacklistsHash ) ;
155+ }
156+
157+ /******************************************************************************/
158+
159+ function onMessageHandler ( request , sender ) {
160+ if ( request && request . what ) {
161+ switch ( request . what ) {
162+ case 'presetBlacklistsLoaded' :
163+ renderBlacklistDetails ( ) ;
164+ remoteBlacklistDetailsChangeHandler ( ) ;
165+ break ;
166+ }
167+ }
168+ }
169+
170+ /******************************************************************************/
171+
61172function initAll ( ) {
62173 var httpsb = gethttpsb ( ) ;
63174 var userSettings = httpsb . userSettings ;
@@ -71,8 +182,7 @@ function initAll() {
71182 $ ( '#delete-unused-session-cookies-after' ) . val ( userSettings . deleteUnusedSessionCookiesAfter ) ;
72183 $ ( '#delete-blacklisted-cookies' ) . attr ( 'checked' , userSettings . deleteCookies === true ) ;
73184 $ ( '#delete-blacklisted-localstorage' ) . attr ( 'checked' , userSettings . deleteLocalStorage ) ;
74- $ ( '#cookie-removed-counter' ) . html ( httpsb . cookieRemovedCounter ) ;
75- $ ( '#localstorage-removed-counter' ) . html ( httpsb . localStorageRemovedCounter ) ;
185+ $ ( '#process-referer' ) . attr ( 'checked' , userSettings . processReferer ) ;
76186 $ ( '#process-behind-the-scene' ) . attr ( 'checked' , userSettings . processBehindTheSceneRequests ) ;
77187 $ ( '#max-logged-requests' ) . val ( userSettings . maxLoggedRequests ) ;
78188
@@ -87,6 +197,8 @@ function initAll() {
87197 $ ( '#auto-whitelist-page-domain' ) . on ( 'change' , function ( ) {
88198 changeUserSettings ( 'autoWhitelistPageDomain' , $ ( this ) . is ( ':checked' ) ) ;
89199 } ) ;
200+ $ ( '#reloadRemoteBlacklists' ) . on ( 'click' , reloadRemoteBlacklistsHandler ) ;
201+ $ ( '#remoteBlacklists' ) . on ( 'change' , '.remoteBlacklistDetails' , remoteBlacklistDetailsChangeHandler ) ;
90202 $ ( '#delete-unused-session-cookies' ) . on ( 'change' , function ( ) {
91203 changeUserSettings ( 'deleteUnusedSessionCookies' , $ ( this ) . is ( ':checked' ) ) ;
92204 } ) ;
@@ -99,6 +211,9 @@ function initAll() {
99211 $ ( '#delete-blacklisted-localstorage' ) . on ( 'change' , function ( ) {
100212 changeUserSettings ( 'deleteLocalStorage' , $ ( this ) . is ( ':checked' ) ) ;
101213 } ) ;
214+ $ ( '#process-referer' ) . on ( 'change' , function ( ) {
215+ changeUserSettings ( 'processReferer' , $ ( this ) . is ( ':checked' ) ) ;
216+ } ) ;
102217 $ ( '#process-behind-the-scene' ) . on ( 'change' , function ( ) {
103218 changeUserSettings ( 'processBehindTheSceneRequests' , $ ( this ) . is ( ':checked' ) ) ;
104219 } ) ;
@@ -118,6 +233,11 @@ function initAll() {
118233 onChangeValueHandler ( $ ( '#max-logged-requests' ) , 'maxLoggedRequests' , 0 , 999 ) ;
119234 window . open ( '' , '_self' ) . close ( ) ;
120235 } ) ;
236+
237+ // To know when the preset blacklist stats change
238+ chrome . runtime . onMessage . addListener ( onMessageHandler ) ;
239+
240+ renderBlacklistDetails ( ) ;
121241}
122242
123243/******************************************************************************/
0 commit comments