From 4cafad66d202433bc358d9c4b8291d593b6e4df8 Mon Sep 17 00:00:00 2001 From: AUTOMATIC <16777216c@gmail.com> Date: Fri, 2 Sep 2022 23:25:29 +0300 Subject: this should send the currently selected image to other tabs instead of the first --- script.js | 31 ++++++++++++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-) (limited to 'script.js') diff --git a/script.js b/script.js index 1d7de7da..5d38b334 100644 --- a/script.js +++ b/script.js @@ -33,7 +33,7 @@ titles = { } function gradioApp(){ - return document.getElementsByTagName('gradio-app')[0]; + return document.getElementsByTagName('gradio-app')[0].shadowRoot; } function addTitles(root){ @@ -47,8 +47,33 @@ function addTitles(root){ document.addEventListener("DOMContentLoaded", function() { var mutationObserver = new MutationObserver(function(m){ - addTitles(gradioApp().shadowRoot); + addTitles(gradioApp()); }); - mutationObserver.observe( gradioApp().shadowRoot, { childList:true, subtree:true }) + mutationObserver.observe( gradioApp(), { childList:true, subtree:true }) }); + +function selected_gallery_index(){ + var gr = gradioApp() + var buttons = gradioApp().querySelectorAll(".gallery-item") + var button = gr.querySelector(".gallery-item.\\!ring-2") + + var result = -1 + buttons.forEach(function(v, i){ if(v==button) { result = i } }) + + return result +} + +function extract_image_from_gallery(gallery){ + if(gallery.length == 1){ + return gallery[0] + } + + index = selected_gallery_index() + + if (index < 0 || index >= gallery.length){ + return [] + } + + return gallery[index]; +} -- cgit v1.2.3