File tree Expand file tree Collapse file tree 1 file changed +42
-0
lines changed Expand file tree Collapse file tree 1 file changed +42
-0
lines changed Original file line number Diff line number Diff 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 ) {
You can’t perform that action at this time.
0 commit comments