From 3ee3bd2dab3ed362bf5be9acfea8db1f16f6fc9c Mon Sep 17 00:00:00 2001 From: Emilia Date: Fri, 29 Dec 2023 19:12:16 -0500 Subject: [PATCH] Superior clipboard manipulation Won't work on non-https connections, but actually works... --- assets/js/screenshot_utility.js | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/assets/js/screenshot_utility.js b/assets/js/screenshot_utility.js index 67a33f5..784b7e5 100644 --- a/assets/js/screenshot_utility.js +++ b/assets/js/screenshot_utility.js @@ -1,16 +1,17 @@ function copy_screenshot(el) { html2canvas(el).then((canvas) => { console.log("Copying image to clipboard"); - let data = canvas.toDataURL(); - - const textArea = document.createElement("textarea"); - textArea.value = data; - - document.body.prepend(textArea); - textArea.select(); - - document.execCommand('copy'); - document.body.removeChild(textArea); + canvas.toBlob((b) => { + try { + navigator.clipboard.write([ + new ClipboardItem({ + 'image/png': b + }) + ]); + } catch (e) { + console.error("Failed to copy!"); + } + }); }); }