Update -> refactor and optimize UI , code ,...
This commit is contained in:
@@ -1,40 +1 @@
|
||||
document.addEventListener("DOMContentLoaded", () => {
|
||||
|
||||
const textarea = document.querySelector("textarea");
|
||||
const form = document.querySelector("form");
|
||||
const copyBtn = document.getElementById("copyBtn");
|
||||
|
||||
|
||||
if (textarea) {
|
||||
textarea.addEventListener("input", () => {
|
||||
textarea.style.height = "auto";
|
||||
textarea.style.height = textarea.scrollHeight + "px";
|
||||
});
|
||||
}
|
||||
|
||||
if (form && textarea) {
|
||||
form.addEventListener("submit", (e) => {
|
||||
if (textarea.value.trim() === "") {
|
||||
e.preventDefault();
|
||||
alert("Paste cannot be empty");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if (copyBtn) {
|
||||
copyBtn.addEventListener("click", () => {
|
||||
const paste = document.getElementById("pasteContent");
|
||||
|
||||
if (!paste) return;
|
||||
|
||||
navigator.clipboard.writeText(paste.innerText)
|
||||
.then(() => {
|
||||
copyBtn.textContent = "Copied!";
|
||||
setTimeout(() => {
|
||||
copyBtn.textContent = "Copy";
|
||||
}, 2000);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
});
|
||||
/* merged into app.js */
|
||||
|
||||
Reference in New Issue
Block a user