From e9ba2d42d6c13bc3f8763c6ccd00fff2519b3152 Mon Sep 17 00:00:00 2001 From: Connum Date: Wed, 21 Sep 2022 00:28:03 +0200 Subject: fix image replacement via clipboard paste or drag and drop on PNG Info tab --- javascript/dragdrop.js | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) (limited to 'javascript/dragdrop.js') diff --git a/javascript/dragdrop.js b/javascript/dragdrop.js index 29e26766..0fb74dba 100644 --- a/javascript/dragdrop.js +++ b/javascript/dragdrop.js @@ -10,13 +10,34 @@ function dropReplaceImage( imgWrap, files ) { } imgWrap.querySelector('.modify-upload button + button, .touch-none + div button + button')?.click(); - window.requestAnimationFrame( () => { + const callback = () => { const fileInput = imgWrap.querySelector('input[type="file"]'); if ( fileInput ) { fileInput.files = files; fileInput.dispatchEvent(new Event('change')); } - }); + }; + + if ( imgWrap.closest('#pnginfo_image') ) { + // special treatment for PNG Info tab, wait for fetch request to finish + const oldFetch = window.fetch; + window.fetch = async (input, options) => { + const response = await oldFetch(input, options); + if ( 'api/predict/' === input ) { + const content = await response.text(); + window.fetch = oldFetch; + window.requestAnimationFrame( () => callback() ); + return new Response(content, { + status: response.status, + statusText: response.statusText, + headers: response.headers + }) + } + return response; + }; + } else { + window.requestAnimationFrame( () => callback() ); + } } function pressClearBtn(hoverElems) { -- cgit v1.2.3