Skip to content

Commit

Permalink
refactor: centralized updatePassword code
Browse files Browse the repository at this point in the history
  • Loading branch information
feildmaster committed Dec 25, 2020
1 parent 2c8e01f commit c114f79
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions src/preload/rememberMe.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,17 @@ function setup() {
const form = document.querySelector('form[action="SignIn"]');
const username = document.querySelector('input[name="login"]');
const password = document.querySelector('input[name="password"]');

function updatePassword(user) {
if (!user) return;
getPassword(user).then((value) => {
if (value) {
username.value = user;
password.value = value;
}
})
}

form.addEventListener('submit', () => {
const save = document.querySelector('input[name="stayConnected"]').checked;
const user = username.value;
Expand All @@ -15,20 +26,9 @@ function setup() {
}
});

password.addEventListener('focus', () => {
const user = username.value;
if (user) getPassword(user).then((value) => password.value = (value || ''));
});
password.addEventListener('focus', () => updatePassword(username.value));

const lastUser = localStorage.getItem('underscript.login.lastUser');
if (lastUser) {
getPassword(lastUser).then((value) => {
if (value) {
username.value = lastUser;
password.value = value;
}
});
}
updatePassword(localStorage.getItem('underscript.login.lastUser'));
}

function getPassword(username) {
Expand Down

0 comments on commit c114f79

Please sign in to comment.