copy paste support

This commit is contained in:
anarch3 2022-11-16 07:36:27 -05:00
parent adeda1b0f5
commit 3bd9d47a3c
4 changed files with 27 additions and 3 deletions

View file

@ -47,6 +47,7 @@ function unhighlight(e) {
}
dropArea.addEventListener('drop', handleDrop, false)
window.addEventListener('paste', handlePaste);
function handleDrop(e) {
let dt = e.dataTransfer
@ -54,6 +55,26 @@ function handleDrop(e) {
handleFiles(files)
}
function handlePaste(e) {
// Get the data of clipboard
const clipboardItems = e.clipboardData.items;
const items = [].slice.call(clipboardItems).filter(function (item) {
// Filter the image items only
return item.type.indexOf('image') !== -1;
});
if (items.length === 0) {
return;
}
const item = items[0];
// Get the blob of image
const blob = item.getAsFile();
console.log(blob)
uploadFile(blob)
previewFile(blob);
}
function handleFiles(files) {
files = [...files]
files.forEach(uploadFile)