Skip to content

Commit 121b538

Browse files
committed
- add clipboard paste support for images with Ctrl+V
- convert clipboard blobs to properly named `File` objects with timestamps - display notifications for successful/failed paste attempts
1 parent f275611 commit 121b538

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

tools/image_converter.html

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -384,6 +384,48 @@ <h2 class="text-xl font-semibold text-gray-800">Conversion Results</h2>
384384
downloadAll();
385385
});
386386

387+
document.addEventListener('paste', async (e) => {
388+
e.preventDefault();
389+
390+
if (!e.clipboardData || !e.clipboardData.items) {
391+
showNotification('No clipboard data found', 'error');
392+
return;
393+
}
394+
395+
const items = Array.from(e.clipboardData.items);
396+
const imageItems = items.filter(item => item.type.startsWith('image/'));
397+
398+
if (imageItems.length === 0) {
399+
showNotification('No image found in clipboard', 'error');
400+
return;
401+
}
402+
403+
const files = [];
404+
let processedCount = 0;
405+
406+
for (const item of imageItems) {
407+
const blob = item.getAsFile();
408+
if (blob) {
409+
// Create a proper File object with a name
410+
const timestamp = new Date().getTime();
411+
const file = new File(
412+
[blob],
413+
`clipboard-image-${timestamp}.png`,
414+
{ type: blob.type }
415+
);
416+
files.push(file);
417+
}
418+
419+
processedCount++;
420+
if (processedCount === imageItems.length) {
421+
if (files.length > 0) {
422+
addFiles(files);
423+
showNotification('Image pasted from clipboard', 'success');
424+
}
425+
}
426+
}
427+
});
428+
387429
// File handling functions
388430
function addFiles(newFiles) {
389431
for (const file of newFiles) {

0 commit comments

Comments
 (0)