Skip to content

Commit 54757b6

Browse files
author
varjolintu
committed
Some fine-tuning
1 parent c92dff8 commit 54757b6

File tree

3 files changed

+46
-48
lines changed

3 files changed

+46
-48
lines changed

keepassxc-browser/popups/popup.html

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959
</div>
6060
</div>
6161

62+
<!-- Loading -->
6263
<div id="initial-state">
6364
<div class="loader"></div> <p data-i18n="popupCheckingStatus"></p>
6465
</div>
@@ -132,6 +133,28 @@
132133
</div>
133134
</div>
134135

136+
<!-- Login list -->
137+
<div id="credentials-list" class="credentials" style="display: none">
138+
<p data-i18n="popupLoginText"></p>
139+
<div id="filter-block">
140+
<label for="login-filter" data-i18n="popupFilterText"></label>
141+
<input type="text" id="login-filter">
142+
</div>
143+
<div id="login-list" class="list-group"></div>
144+
</div>
145+
146+
<!-- HTTP Auth login list-->
147+
<div id="http-auth-credentials-list" class="credentials" style="display: none">
148+
<p data-i18n="popupAuthText"></p>
149+
<div id="http-auth-login-list" class="list-group"></div>
150+
<p>
151+
<button id="btn-dismiss" class="btn btn-sm btn-danger" data-i18n="[title]dismissHttpAuthButtonTitle">
152+
<i class="fa fa-remove" aria-hidden="true"></i>
153+
<span data-i18n="popupButtonDismissHttpAuth"></span>
154+
</button>
155+
</p>
156+
</div>
157+
135158
<!-- Username-only field detected message -->
136159
<div id="username-field-detected">
137160
<hr>
@@ -155,28 +178,6 @@
155178
</button>
156179
</div>
157180
</div>
158-
159-
<!-- Login list -->
160-
<div id="credentials-list" class="credentials" style="display: none">
161-
<p data-i18n="popupLoginText"></p>
162-
<div id="filter-block">
163-
<label for="login-filter" data-i18n="popupFilterText"></label>
164-
<input type="text" id="login-filter">
165-
</div>
166-
<div id="login-list" class="list-group"></div>
167-
</div>
168-
169-
<!-- HTTP Auth login list-->
170-
<div id="http-auth-credentials-list" class="credentials" style="display: none">
171-
<p data-i18n="popupAuthText"></p>
172-
<div id="http-auth-login-list" class="list-group"></div>
173-
<p>
174-
<button id="btn-dismiss" class="btn btn-sm btn-danger" data-i18n="[title]dismissHttpAuthButtonTitle">
175-
<i class="fa fa-remove" aria-hidden="true"></i>
176-
<span data-i18n="popupButtonDismissHttpAuth"></span>
177-
</button>
178-
</p>
179-
</div>
180181
</div>
181182
</body>
182183
</html>

keepassxc-browser/popups/popup.js

Lines changed: 17 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,7 @@ const POLLING_INTERVAL = 1000; // ms
44
let previousStatus;
55
let 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
})();

keepassxc-browser/popups/popup_functions.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@ async function initializeLoginList() {
6767
removeAllChildren(loginList);
6868

6969
for (const [ i, login ] of logins.entries()) {
70-
const uuid = login.uuid;
7170
const a = document.createElement('a');
7271
a.textContent = login.text;
7372
a.setAttribute('class', 'list-group-item');
@@ -82,7 +81,7 @@ async function initializeLoginList() {
8281
browser.tabs.sendMessage(tab?.id, {
8382
action: 'fill_user_pass_with_specific_login',
8483
id: Number(id),
85-
uuid: uuid
84+
uuid: login?.uuid
8685
});
8786

8887
close();
@@ -115,7 +114,6 @@ async function initializeLoginList() {
115114
}
116115

117116
// Intitializes the login list for HTTP Basic Auth
118-
// TODO: Combine with the listing function above?
119117
async function initializeHttpAuthLoginList() {
120118
const data = await getLoginData();
121119
const loginList = document.getElementById('http-auth-login-list');
@@ -125,8 +123,8 @@ async function initializeHttpAuthLoginList() {
125123

126124
for (const [ i, login ] of data.logins.entries()) {
127125
const a = document.createElement('a');
128-
a.setAttribute('class', 'list-group-item');
129126
a.textContent = login.login + ' (' + login.name + ')';
127+
a.setAttribute('class', 'list-group-item');
130128
a.setAttribute('id', '' + i);
131129

132130
a.addEventListener('click', (e) => {
@@ -148,7 +146,10 @@ async function initializeHttpAuthLoginList() {
148146
}
149147

150148
(async () => {
151-
if (document.readyState === 'complete' || (document.readyState !== 'loading' && !document.documentElement.doScroll)) {
149+
if (
150+
document.readyState === 'complete' ||
151+
(document.readyState !== 'loading' && !document.documentElement.doScroll)
152+
) {
152153
await initSettings();
153154
} else {
154155
document.addEventListener('DOMContentLoaded', initSettings);

0 commit comments

Comments
 (0)