Skip to content

Commit a8f8165

Browse files
committed
- improve copyoutput method
1 parent 60fd1f7 commit a8f8165

File tree

1 file changed

+13
-10
lines changed

1 file changed

+13
-10
lines changed

tools/verbose_o_matic.html

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -477,20 +477,23 @@ <h1>Verbose-O-Matic</h1>
477477
}
478478
}
479479

480-
function copyOutput() {
481-
const output = document.getElementById('outputText').textContent;
482-
navigator.clipboard.writeText(output).then(() => {
483-
const btn = event.target.closest('.copy-btn');
484-
const originalHTML = btn.innerHTML;
480+
async function copyOutput(event) {
481+
const btn = event.target.closest('.copy-btn');
482+
const originalContent = btn.innerHTML;
483+
484+
try {
485+
await navigator.clipboard.writeText(document.getElementById('outputText').textContent);
486+
485487
btn.classList.add('copied');
486488
btn.innerHTML = '<svg width="16" height="16" fill="currentColor" viewBox="0 0 16 16"><path d="M13.854 3.646a.5.5 0 0 1 0 .708l-7 7a.5.5 0 0 1-.708 0l-3.5-3.5a.5.5 0 1 1 .708-.708L6.5 10.293l6.646-6.647a.5.5 0 0 1 .708 0z"/></svg> Copied!';
489+
487490
setTimeout(() => {
488491
btn.classList.remove('copied');
489-
btn.innerHTML = originalHTML
490-
}, 2000)
491-
}).catch(err => {
492-
showAlert('Failed to copy to clipboard', 'error')
493-
})
492+
btn.innerHTML = originalContent;
493+
}, 2000);
494+
} catch {
495+
showAlert('Failed to copy to clipboard', 'error');
496+
}
494497
}
495498

496499
init()

0 commit comments

Comments
 (0)