Added unsupported format handling

This commit is contained in:
2021-05-03 21:32:25 +02:00
parent b61c4c5239
commit bda3cfe94c

View File

@@ -102,7 +102,14 @@ function rgbToHex(r, g, b) {
const file = document.getElementById("file"); const file = document.getElementById("file");
file.addEventListener("change", function () { file.addEventListener("change", function () {
var format = file.value.split(".")[1].toLowerCase();
var allowedFormats = ["png", "jpg"];
if (allowedFormats.includes(format)) {
document.getElementById('img').src = window.URL.createObjectURL(this.files[0]); document.getElementById('img').src = window.URL.createObjectURL(this.files[0]);
} else {
alert("Unsupported file format: " + format + "\nSupported formats: " + allowedFormats);
}
renew(); renew();
}); });
@@ -116,12 +123,18 @@ body.addEventListener("dragover", function () {
}); });
}); });
const custom = document.getElementById("custom"); const custom = document.getElementById("custom");
custom.addEventListener("keyup", function () { custom.addEventListener("keyup", function () {
if (custom.value.length == 7) { if (custom.value.length == 7) {
custom.value = custom.value.toLowerCase();
document.getElementById("img").style.borderColor = custom.value; document.getElementById("img").style.borderColor = custom.value;
copyToClipboard(custom.value);
} }
}); });
custom.addEventListener("dblclick", function () {
custom.value = "#ffffff";
document.getElementById("img").style.borderColor = custom.value;
copyToClipboard(custom.value);
});
renew(); renew();