Clean up sendToControlnet()
parent
9516b8a512
commit
04ebf76e16
|
|
@ -32,33 +32,26 @@ async function sendToControlnet(img, tab, index) {
|
|||
dt.items.add(file);
|
||||
const list = dt.files;
|
||||
|
||||
const selector = `#${tab}_script_container`;
|
||||
window["switch_to_" + tab]();
|
||||
|
||||
if (tab === "txt2img"){
|
||||
switch_to_txt2img();
|
||||
} else if (tab === "img2img") {
|
||||
switch_to_img2img();
|
||||
}
|
||||
|
||||
const accordion = gradioApp().querySelector(selector).querySelector("#controlnet > .label-wrap > .icon")
|
||||
if (accordion.style.transform == "rotate(90deg)") {
|
||||
const controlnet = gradioApp().querySelector(`#${tab}_script_container #controlnet`);
|
||||
const accordion = controlnet.querySelector(":scope > .label-wrap")
|
||||
if (!accordion.classList.contains("open")) {
|
||||
accordion.click();
|
||||
}
|
||||
|
||||
const controlnetDiv = gradioApp().querySelector(selector).querySelector("#controlnet");
|
||||
const tabs = controlnetDiv.querySelectorAll("div.tab-nav > button");
|
||||
const tabs = controlnet.querySelectorAll("div.tab-nav > button");
|
||||
|
||||
if (tabs !== null && tabs.length > 1) {
|
||||
tabs[index].click();
|
||||
}
|
||||
|
||||
let input = gradioApp().querySelector(selector).querySelector("#controlnet").querySelectorAll("input[type='file']")[index * 2];
|
||||
const input = controlnet.querySelectorAll("input[type='file']")[index * 2];
|
||||
|
||||
if (input == null) {
|
||||
const callback = (observer) => {
|
||||
input = gradioApp().querySelector(selector).querySelector("#controlnet").querySelector("input[type='file']");
|
||||
input = controlnet.querySelector("input[type='file']");
|
||||
if (input == null) {
|
||||
console.error('input[type=file] NOT exists');
|
||||
return;
|
||||
} else {
|
||||
setImage(input, list);
|
||||
|
|
@ -66,7 +59,7 @@ async function sendToControlnet(img, tab, index) {
|
|||
}
|
||||
}
|
||||
const observer = new MutationObserver(callback);
|
||||
observer.observe(gradioApp().querySelector(selector).querySelector("#controlnet"), { childList: true });
|
||||
observer.observe(controlnet, { childList: true });
|
||||
} else {
|
||||
setImage(input, list);
|
||||
}
|
||||
|
|
@ -74,9 +67,9 @@ async function sendToControlnet(img, tab, index) {
|
|||
|
||||
function setImage(input, list) {
|
||||
try {
|
||||
if (input.previousElementSibling
|
||||
&& input.previousElementSibling.previousElementSibling
|
||||
&& input.previousElementSibling.previousElementSibling.querySelector("button[aria-label='Clear']")) {
|
||||
if (input.previousElementSibling &&
|
||||
input.previousElementSibling.previousElementSibling &&
|
||||
input.previousElementSibling.previousElementSibling.querySelector("button[aria-label='Clear']")) {
|
||||
input.previousElementSibling.previousElementSibling.querySelector("button[aria-label='Clear']").click()
|
||||
}
|
||||
} catch (e) {
|
||||
|
|
@ -84,6 +77,6 @@ function setImage(input, list) {
|
|||
}
|
||||
input.value = "";
|
||||
input.files = list;
|
||||
const event = new Event('change', { 'bubbles': true, "composed": true });
|
||||
const event = new Event("change", { "bubbles": true, "composed": true });
|
||||
input.dispatchEvent(event);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue