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) {
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!");
}
});
});
}