You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
43 lines
944 B
43 lines
944 B
$('#newAccountForm').addEventListener('submit', (e) => {
|
|
e.preventDefault();
|
|
|
|
chrome.storage.sync.get('accounts', ({ accounts }) => {
|
|
if (!accounts) accounts = [];
|
|
|
|
const school = $('#school').value;
|
|
const username = $('#username').value;
|
|
|
|
if (accounts.find((account) => account.username == username && account.school == school)) {
|
|
const _errorMessage = create('p');
|
|
|
|
_errorMessage.innerHTML = 'Account bestaat al.';
|
|
_errorMessage.classList.add('error-message');
|
|
|
|
$('#message').innerHTML = '';
|
|
|
|
$('#message').appendChild(_errorMessage);
|
|
|
|
return;
|
|
}
|
|
|
|
const newAccount = {
|
|
school,
|
|
username,
|
|
password: $('#password').value,
|
|
};
|
|
|
|
if (accounts.length == 0 || $('#primaryAccount').checked) {
|
|
chrome.storage.sync.set({ primaryAccount: username });
|
|
}
|
|
|
|
chrome.storage.sync.set(
|
|
{
|
|
accounts: [...accounts, newAccount],
|
|
},
|
|
() => {
|
|
location.href = '@pages/options.html';
|
|
}
|
|
);
|
|
});
|
|
});
|