41 lines
1.1 KiB
JavaScript
41 lines
1.1 KiB
JavaScript
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);
|
|
});
|
|
});
|
|
}
|
|
|
|
});
|