Skip to content

Commit

Permalink
refactor: made new showError func and formated some EventListeners
Browse files Browse the repository at this point in the history
  • Loading branch information
Random-user420 committed Oct 24, 2024
1 parent de027e9 commit b635e70
Showing 1 changed file with 22 additions and 22 deletions.
44 changes: 22 additions & 22 deletions popup/popup.js
Original file line number Diff line number Diff line change
@@ -1,36 +1,29 @@
// chrome.tabs..... { <identifier>: true, parameter… });
document.getElementById('changeColorBtn').addEventListener('click', () => {
const color = document.getElementById('colorPicker').value;
chrome.tabs.query({active: true, currentWindow: true}, (tabs) => {
chrome.tabs.sendMessage(tabs[0].id, {changeColorBtn: true, color: color}, (response) => {
chrome.tabs.sendMessage(tabs[0].id, {
changeColorBtn: true,
color: document.getElementById('colorPicker').value
}, (response) => {
if (response !== undefined && response.faieldColorValidation) {
const errorMessage = document.getElementById('error-message-color');
errorMessage.innerHTML = "Color must be written as #RRGGBB";
errorMessage.style.display = 'block';
showError('error-message-color', "Color must be written as #RRGGBB");
}
});
});
});

document.getElementById('autologinBtn').addEventListener('click', () => {
const username = document.getElementById('autologinUsername').value;
const password = document.getElementById('autologinPassword').value;
const enabled = document.getElementById('autologinCheckbox').checked;
const encryptEnabled = document.getElementById('autologinPasswordProtection').checked;
const key = document.getElementById('autologinEncryptionPassword').value;
chrome.tabs.query({active: true, currentWindow: true}, (tabs) => {
chrome.tabs.sendMessage(tabs[0].id, {
autologinBtn: true,
pawssword: password,
username: username,
enabled: enabled,
encryptEnabled: encryptEnabled,
key: key
pawssword: document.getElementById('autologinPassword').value,
username: document.getElementById('autologinUsername').value,
enabled: document.getElementById('autologinCheckbox').checked,
encryptEnabled: document.getElementById('autologinPasswordProtection').checked,
key: document.getElementById('autologinEncryptionPassword').value
}, (response) => {
if (response !== undefined && response.failedInputValidation) {
const errorMessage = document.getElementById('error-message-login');
errorMessage.innerHTML = 'Input Validation Failed! Please Check Your Input and Try Again. View the <a style="color: white; font-weight: bold;" href="https://github.com/Random-user420/bestKabu" target="_blank">GitHub Repo</a> for more info.';
errorMessage.style.display = 'block';
showError('error-message-login', 'Input Validation Failed! Please Check Your Input and Try Again. View the <a style="color: white; font-weight: bold;" href="https://github.com/Random-user420/bestKabu" target="_blank">GitHub Repo</a> for more info.');
}
});
});
Expand All @@ -56,11 +49,12 @@ document.getElementById('darkModeToggle').addEventListener('click', () => {
document.getElementById('autologinEncryptionBtn').addEventListener('click', () => {
const key = document.getElementById('autologinEncryptionPassword').value;
chrome.tabs.query({active: true, currentWindow: true}, (tabs) => {
chrome.tabs.sendMessage(tabs[0].id, {autologinEncryptionBtn: true, key: key}, (response) => {
chrome.tabs.sendMessage(tabs[0].id, {
autologinEncryptionBtn: true, key: key
}, (response) => {
if (response !== undefined && response.failedInputValidation) {
const errorMessage = document.getElementById('error-message-login');
errorMessage.textContent = "Input Validation Failed! Please Check Your Input and Try Again. View the GitHub Repo for more info.";
errorMessage.style.display = 'block'; }
showError('error-message-login', "Input Validation Failed! Please Check Your Input and Try Again. View the GitHub Repo for more info.");
}
});
});
});
Expand Down Expand Up @@ -106,5 +100,11 @@ function getDarkMode() {
});
}

function showError(id, message) {
const errorMessage = document.getElementById(id);
errorMessage.textContent = message;
errorMessage.style.display = 'block';
}

getAutologinState();
getDarkMode();

0 comments on commit b635e70

Please sign in to comment.