updated color randomizer, allows for custom color visualization now too

This commit is contained in:
zyqunix 2024-12-26 15:57:46 +01:00
parent 71924663d8
commit 4008467462
8 changed files with 106 additions and 8 deletions

View file

@ -2,6 +2,8 @@ const colorButton = document.getElementById('colorButton');
const fullColor = document.getElementById('fullColor');
const main = document.getElementById('main');
const offscreenAlert = document.getElementById('offscreenalert');
const colorInput = document.getElementById('colorInput');
const inputButton = document.getElementById('inputButton');
const chars = "0123456789ABCDEF";
@ -38,3 +40,25 @@ main.addEventListener('click', () => {
const colorText = fullColor.textContent || fullColor.innerHTML;
copyToClipboard(colorText).then(showAlert);
});
colorInput.addEventListener("keydown", function(event) {
if (event.key === "Enter") {
const inputValue = colorInput.value;
if (/^#[0-9A-F]{6}$/i.test(inputValue)) {
applyColor(inputValue);
} else {
document.getElementById('hint').innerHTML = "Invalid color format. Please enter a valid hex color code. EG #aabbcc";
}
event.preventDefault();
}
});
inputButton.addEventListener("click", function(event) {
const inputValue = colorInput.value;
if (/^#[0-9A-F]{6}$/i.test(inputValue)) {
applyColor(inputValue);
} else {
document.getElementById('hint').innerHTML = "Invalid color format. Please enter a valid hex color code. EG #aabbcc";
}
event.preventDefault();
});