@@ -4,15 +4,7 @@ const POLLING_INTERVAL = 1000; // ms
44let previousStatus ;
55let reloadCount = 0 ;
66
7- HTMLElement . prototype . show = function ( ) {
8- this . style . display = 'block' ;
9- } ;
10-
11- HTMLElement . prototype . hide = function ( ) {
12- this . style . display = 'none' ;
13- } ;
14-
15- function statusResponse ( response ) {
7+ function hideAll ( ) {
168 $ ( '#initial-state' ) . hide ( ) ;
179 $ ( '#error-encountered' ) . hide ( ) ;
1810 $ ( '#need-reconfigure' ) . hide ( ) ;
@@ -24,8 +16,11 @@ function statusResponse(response) {
2416 $ ( '#database-not-opened' ) . hide ( ) ;
2517 $ ( '#credentials-list' ) . hide ( ) ;
2618 $ ( '#http-auth-credentials-list' ) . hide ( ) ;
19+ }
2720
28- previousStatus = response ;
21+ function handleStatusResponse ( response ) {
22+ console . log ( 'Handling response:' , response ) ;
23+ hideAll ( ) ;
2924
3025 // Error situations
3126 if ( ! response . keePassXCAvailable ) {
@@ -63,7 +58,7 @@ function statusResponse(response) {
6358 return ;
6459 }
6560
66- // Show the popup content
61+ // Show the popup content based on status
6762 if ( response ?. popupData ?. popup === PopupState . LOGIN ) {
6863 $ ( '#credentials-list' ) . show ( ) ;
6964 $ ( '#configured-and-associated' ) . hide ( ) ;
@@ -82,10 +77,12 @@ function statusResponse(response) {
8277
8378 $ ( '#lock-database-button' ) . show ( ) ;
8479
80+ // Show button for adding Username-Only Detection for the site
8581 if ( response . usernameFieldDetected ) {
8682 $ ( '#username-field-detected' ) . show ( ) ;
8783 }
8884
85+ // Show button for allowing Cross-Origin IFrames for the site
8986 if ( response . iframeDetected ) {
9087 $ ( '#iframe-detected' ) . show ( ) ;
9188 }
@@ -127,7 +124,7 @@ const sendMessageToTab = async function(message) {
127124 } ) ;
128125
129126 $ ( '#reload-status-button' ) . addEventListener ( 'click' , async ( ) => {
130- statusResponse ( await browser . runtime . sendMessage ( {
127+ handleStatusResponse ( await browser . runtime . sendMessage ( {
131128 action : 'reconnect'
132129 } ) ) ;
133130
@@ -139,7 +136,7 @@ const sendMessageToTab = async function(message) {
139136 } ) ;
140137
141138 $ ( '#reopen-database-button' ) . addEventListener ( 'click' , async ( ) => {
142- statusResponse ( await browser . runtime . sendMessage ( {
139+ handleStatusResponse ( await browser . runtime . sendMessage ( {
143140 action : 'get_status' ,
144141 args : [ false , true ] // Set forcePopup to true
145142 } ) ) ;
@@ -152,13 +149,13 @@ const sendMessageToTab = async function(message) {
152149 return ;
153150 }
154151
155- statusResponse ( await browser . runtime . sendMessage ( {
152+ handleStatusResponse ( await browser . runtime . sendMessage ( {
156153 action : 'get_status'
157154 } ) ) ;
158155 } ) ;
159156
160157 $ ( '#lock-database-button' ) . addEventListener ( 'click' , async ( ) => {
161- statusResponse ( await browser . runtime . sendMessage ( {
158+ handleStatusResponse ( await browser . runtime . sendMessage ( {
162159 action : 'lock_database'
163160 } ) ) ;
164161 } ) ;
@@ -207,17 +204,16 @@ const sendMessageToTab = async function(message) {
207204 }
208205
209206 // Get status right after popup has been opened
210- statusResponse ( await getNewStatus ( ) ) ;
207+ handleStatusResponse ( await getNewStatus ( ) ) ;
211208
212209 // Poll status
213210 setInterval ( async ( ) => {
214211 // Check if the popup state has been changed or database has been opened/closed
215212 const currentStatus = await getNewStatus ( ) ;
216- if ( previousStatus &&
217- ( previousStatus ?. popupData ?. popup !== currentStatus ?. popupData ?. popup ||
218- previousStatus ?. databaseClosed !== currentStatus ?. databaseClosed )
219- ) {
220- statusResponse ( currentStatus ) ;
213+ if ( previousStatus ?. popupData ?. popup !== currentStatus ?. popupData ?. popup
214+ || previousStatus ?. databaseClosed !== currentStatus ?. databaseClosed ) {
215+ previousStatus = currentStatus ;
216+ handleStatusResponse ( currentStatus ) ;
221217 }
222218 } , POLLING_INTERVAL ) ;
223219} ) ( ) ;
0 commit comments