@@ -4,15 +4,7 @@ const POLLING_INTERVAL = 1000; // ms
4
4
let previousStatus ;
5
5
let reloadCount = 0 ;
6
6
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 ( ) {
16
8
$ ( '#initial-state' ) . hide ( ) ;
17
9
$ ( '#error-encountered' ) . hide ( ) ;
18
10
$ ( '#need-reconfigure' ) . hide ( ) ;
@@ -24,8 +16,11 @@ function statusResponse(response) {
24
16
$ ( '#database-not-opened' ) . hide ( ) ;
25
17
$ ( '#credentials-list' ) . hide ( ) ;
26
18
$ ( '#http-auth-credentials-list' ) . hide ( ) ;
19
+ }
27
20
28
- previousStatus = response ;
21
+ function handleStatusResponse ( response ) {
22
+ console . log ( 'Handling response:' , response ) ;
23
+ hideAll ( ) ;
29
24
30
25
// Error situations
31
26
if ( ! response . keePassXCAvailable ) {
@@ -63,7 +58,7 @@ function statusResponse(response) {
63
58
return ;
64
59
}
65
60
66
- // Show the popup content
61
+ // Show the popup content based on status
67
62
if ( response ?. popupData ?. popup === PopupState . LOGIN ) {
68
63
$ ( '#credentials-list' ) . show ( ) ;
69
64
$ ( '#configured-and-associated' ) . hide ( ) ;
@@ -82,10 +77,12 @@ function statusResponse(response) {
82
77
83
78
$ ( '#lock-database-button' ) . show ( ) ;
84
79
80
+ // Show button for adding Username-Only Detection for the site
85
81
if ( response . usernameFieldDetected ) {
86
82
$ ( '#username-field-detected' ) . show ( ) ;
87
83
}
88
84
85
+ // Show button for allowing Cross-Origin IFrames for the site
89
86
if ( response . iframeDetected ) {
90
87
$ ( '#iframe-detected' ) . show ( ) ;
91
88
}
@@ -127,7 +124,7 @@ const sendMessageToTab = async function(message) {
127
124
} ) ;
128
125
129
126
$ ( '#reload-status-button' ) . addEventListener ( 'click' , async ( ) => {
130
- statusResponse ( await browser . runtime . sendMessage ( {
127
+ handleStatusResponse ( await browser . runtime . sendMessage ( {
131
128
action : 'reconnect'
132
129
} ) ) ;
133
130
@@ -139,7 +136,7 @@ const sendMessageToTab = async function(message) {
139
136
} ) ;
140
137
141
138
$ ( '#reopen-database-button' ) . addEventListener ( 'click' , async ( ) => {
142
- statusResponse ( await browser . runtime . sendMessage ( {
139
+ handleStatusResponse ( await browser . runtime . sendMessage ( {
143
140
action : 'get_status' ,
144
141
args : [ false , true ] // Set forcePopup to true
145
142
} ) ) ;
@@ -152,13 +149,13 @@ const sendMessageToTab = async function(message) {
152
149
return ;
153
150
}
154
151
155
- statusResponse ( await browser . runtime . sendMessage ( {
152
+ handleStatusResponse ( await browser . runtime . sendMessage ( {
156
153
action : 'get_status'
157
154
} ) ) ;
158
155
} ) ;
159
156
160
157
$ ( '#lock-database-button' ) . addEventListener ( 'click' , async ( ) => {
161
- statusResponse ( await browser . runtime . sendMessage ( {
158
+ handleStatusResponse ( await browser . runtime . sendMessage ( {
162
159
action : 'lock_database'
163
160
} ) ) ;
164
161
} ) ;
@@ -207,17 +204,16 @@ const sendMessageToTab = async function(message) {
207
204
}
208
205
209
206
// Get status right after popup has been opened
210
- statusResponse ( await getNewStatus ( ) ) ;
207
+ handleStatusResponse ( await getNewStatus ( ) ) ;
211
208
212
209
// Poll status
213
210
setInterval ( async ( ) => {
214
211
// Check if the popup state has been changed or database has been opened/closed
215
212
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 ) ;
221
217
}
222
218
} , POLLING_INTERVAL ) ;
223
219
} ) ( ) ;
0 commit comments