From: Ardis Lu Date: Sun, 17 Mar 2024 04:16:04 +0000 (-0700) Subject: Add clipboard.writeText fallback for Firefox X-Git-Url: https://git.ardis.lu/?a=commitdiff_plain;h=a3a2d49973c41f0037a5d50f3281a3c3ec056277;p=event-hashes Add clipboard.writeText fallback for Firefox --- diff --git a/index.html b/index.html index 68a8b6c..d02febc 100644 --- a/index.html +++ b/index.html @@ -405,11 +405,16 @@ document.querySelector('#copy-table').addEventListener('click', async e => { const table = document.querySelector('table'); - const data = [new ClipboardItem({ - 'text/plain': new Blob([table.innerText], { type: 'text/plain' }), - 'text/html': new Blob([table.outerHTML], { type: 'text/html' }) - })]; - navigator.clipboard.write(data); + if (window.ClipboardItem === undefined) { + navigator.clipboard.writeText(table.innerText); + } + else { + const data = [new ClipboardItem({ + 'text/plain': new Blob([table.innerText], { type: 'text/plain' }), + 'text/html': new Blob([table.outerHTML], { type: 'text/html' }) + })]; + navigator.clipboard.write(data); + } debounceButton(e.target, clipboardSVG, 'Copy table to clipboard'); });