Superior clipboard manipulation

Won't work on non-https connections, but actually works...
This commit is contained in:
Emilia Allison 2023-12-29 19:12:16 -05:00
parent 08f647cd01
commit 3ee3bd2dab
Signed by: emilia
GPG Key ID: 7A3F8997BFE894E0
1 changed files with 11 additions and 10 deletions

View File

@ -1,16 +1,17 @@
function copy_screenshot(el) { function copy_screenshot(el) {
html2canvas(el).then((canvas) => { html2canvas(el).then((canvas) => {
console.log("Copying image to clipboard"); console.log("Copying image to clipboard");
let data = canvas.toDataURL(); canvas.toBlob((b) => {
try {
const textArea = document.createElement("textarea"); navigator.clipboard.write([
textArea.value = data; new ClipboardItem({
'image/png': b
document.body.prepend(textArea); })
textArea.select(); ]);
} catch (e) {
document.execCommand('copy'); console.error("Failed to copy!");
document.body.removeChild(textArea); }
});
}); });
} }