Skip to content

Commit c114f79

Browse files
committed
refactor: centralized updatePassword code
1 parent 2c8e01f commit c114f79

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

src/preload/rememberMe.js

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,17 @@ function setup() {
44
const form = document.querySelector('form[action="SignIn"]');
55
const username = document.querySelector('input[name="login"]');
66
const password = document.querySelector('input[name="password"]');
7+
8+
function updatePassword(user) {
9+
if (!user) return;
10+
getPassword(user).then((value) => {
11+
if (value) {
12+
username.value = user;
13+
password.value = value;
14+
}
15+
})
16+
}
17+
718
form.addEventListener('submit', () => {
819
const save = document.querySelector('input[name="stayConnected"]').checked;
920
const user = username.value;
@@ -15,20 +26,9 @@ function setup() {
1526
}
1627
});
1728

18-
password.addEventListener('focus', () => {
19-
const user = username.value;
20-
if (user) getPassword(user).then((value) => password.value = (value || ''));
21-
});
29+
password.addEventListener('focus', () => updatePassword(username.value));
2230

23-
const lastUser = localStorage.getItem('underscript.login.lastUser');
24-
if (lastUser) {
25-
getPassword(lastUser).then((value) => {
26-
if (value) {
27-
username.value = lastUser;
28-
password.value = value;
29-
}
30-
});
31-
}
31+
updatePassword(localStorage.getItem('underscript.login.lastUser'));
3232
}
3333

3434
function getPassword(username) {

0 commit comments

Comments
 (0)