aboutsummaryrefslogtreecommitdiffstats
path: root/script.js
diff options
context:
space:
mode:
authorAUTOMATIC <16777216c@gmail.com>2022-09-02 20:25:29 +0000
committerAUTOMATIC <16777216c@gmail.com>2022-09-02 20:25:29 +0000
commit4cafad66d202433bc358d9c4b8291d593b6e4df8 (patch)
treefe5c7ef5320bc7b7ae8957b1a15835660aebe270 /script.js
parentb541c8ba3efacd39e08b6d5971bdd45a9e09514e (diff)
downloadstable-diffusion-webui-gfx803-4cafad66d202433bc358d9c4b8291d593b6e4df8.tar.gz
stable-diffusion-webui-gfx803-4cafad66d202433bc358d9c4b8291d593b6e4df8.tar.bz2
stable-diffusion-webui-gfx803-4cafad66d202433bc358d9c4b8291d593b6e4df8.zip
this should send the currently selected image to other tabs instead of the first
Diffstat (limited to 'script.js')
-rw-r--r--script.js31
1 files changed, 28 insertions, 3 deletions
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];
+}