Show temporary status message when copied to clipboard

This commit is contained in:
Debanjum Singh Solanky
2023-11-27 13:05:31 -08:00
parent 491a1a949a
commit 0430fa67b6
2 changed files with 18 additions and 2 deletions

View File

@@ -15,11 +15,19 @@
let chatOptions = []; let chatOptions = [];
function copyProgrammaticOutput(event) { function copyProgrammaticOutput(event) {
// Remove the first 4 characters which are the "Copy" button // Remove the first 4 characters which are the "Copy" button
const originalCopyText = event.target.parentNode.textContent.trim().slice(0, 4);
const programmaticOutput = event.target.parentNode.textContent.trim().slice(4); const programmaticOutput = event.target.parentNode.textContent.trim().slice(4);
navigator.clipboard.writeText(programmaticOutput).then(() => { navigator.clipboard.writeText(programmaticOutput).then(() => {
console.log("Programmatic output copied to clipboard"); event.target.textContent = "✅ Copied to clipboard!";
setTimeout(() => {
event.target.textContent = originalCopyText;
}, 1000);
}).catch((error) => { }).catch((error) => {
console.error("Error copying programmatic output to clipboard:", error); console.error("Error copying programmatic output to clipboard:", error);
event.target.textContent = "⛔️ Failed to copy!";
setTimeout(() => {
event.target.textContent = originalCopyText;
}, 1000);
}); });
} }

View File

@@ -24,11 +24,19 @@ To get started, just start typing below. You can also type / to see a list of co
let chatOptions = []; let chatOptions = [];
function copyProgrammaticOutput(event) { function copyProgrammaticOutput(event) {
// Remove the first 4 characters which are the "Copy" button // Remove the first 4 characters which are the "Copy" button
const originalCopyText = event.target.parentNode.textContent.trim().slice(0, 4);
const programmaticOutput = event.target.parentNode.textContent.trim().slice(4); const programmaticOutput = event.target.parentNode.textContent.trim().slice(4);
navigator.clipboard.writeText(programmaticOutput).then(() => { navigator.clipboard.writeText(programmaticOutput).then(() => {
console.log("Programmatic output copied to clipboard"); event.target.textContent = "✅ Copied to clipboard!";
setTimeout(() => {
event.target.textContent = originalCopyText;
}, 1000);
}).catch((error) => { }).catch((error) => {
console.error("Error copying programmatic output to clipboard:", error); console.error("Error copying programmatic output to clipboard:", error);
event.target.textContent = "⛔️ Failed to copy!";
setTimeout(() => {
event.target.textContent = originalCopyText;
}, 1000);
}); });
} }