Put an end to all the tab shenanigans

main
zahand 2023-04-05 05:09:54 +03:30
parent f8ff9bcab3
commit 27663f3366
2 changed files with 22 additions and 25 deletions

View File

@ -1,31 +1,26 @@
function setupNPW() { function setupNPW() {
fixAccordion(); fixAccordion('tab_txt2img');
fixInputs(); fixAccordion('tab_img2img');
fixInputs('tab_txt2img');
fixInputs('tab_img2img');
} }
function fixInputs() { function fixInputs(tab) {
const npwSlider_t2i = document.querySelector("#tab_txt2img #npw-slider"); const npwSlider = document.querySelector(`#${tab} #npw-slider`);
const npwSlider_i2i = document.querySelector("#tab_img2img #npw-slider");
npwSlider_t2i.querySelector('.head').remove(); npwSlider.querySelector('.head').remove();
npwSlider_i2i.querySelector('.head').remove();
const newSpan = document.createElement("span"); const newSpan = document.createElement("span");
newSpan.innerHTML = "Negative Prompt Weight"; newSpan.innerHTML = "Negative Prompt Weight";
const ancestor_t2i = npwSlider_t2i.parentNode.parentNode.parentNode; const ancestor = npwSlider.parentNode.parentNode.parentNode;
ancestor_t2i.insertBefore(newSpan, ancestor_t2i.firstChild); ancestor.insertBefore(newSpan, ancestor.firstChild);
const ancestor_i2i = npwSlider_i2i.parentNode.parentNode.parentNode;
ancestor_i2i.insertBefore(newSpan.cloneNode(true), ancestor_i2i.firstChild);
document.querySelector('#tab_txt2img #npw-number input[type="number"]').setAttribute("step", "0.01"); document.querySelector(`#${tab} #npw-number input[type="number"]`).setAttribute("step", "0.01");
document.querySelector('#tab_img2img #npw-number input[type="number"]').setAttribute("step", "0.01");
} }
function fixAccordion() { function fixAccordion(tab) {
document.querySelector('#tab_txt2img #npw .icon').remove(); document.querySelector(`#${tab} #npw .icon`).remove();
document.querySelector('#tab_img2img #npw .icon').remove(); document.querySelector(`#${tab} #npw .open`).remove();
document.querySelector('#tab_txt2img #npw .open').remove();
document.querySelector('#tab_img2img #npw .open').remove();
} }
onUiLoaded(setupNPW); onUiLoaded(setupNPW);

View File

@ -26,10 +26,12 @@ class Script(scripts.Script):
reset_but = gr.Button(value='', elem_id='npw-x').style(full_width=False, size='sm') reset_but = gr.Button(value='', elem_id='npw-x').style(full_width=False, size='sm')
js = """(v) => { js = """(v) => {
let t=document.querySelector('#txt2img_negative_token_counter'), ['#txt2img_negative_token_counter', '#img2img_negative_token_counter'].forEach((selector, index) => {
i=document.querySelector('#img2img_negative_token_counter'); const element = document.querySelector(selector);
t.style.cssText+=`outline:4px solid rgba(255,0,128,${Math.sqrt(Math.abs(v-1))}); border-radius: 0.4em !important;` if (document.querySelector(`#tab_${index ? 'img2img' : 'txt2img'}`).style.display === 'block') {
i.style.cssText+=`outline:4px solid rgba(255,0,128,${Math.sqrt(Math.abs(v-1))}); border-radius: 0.4em !important;` element.style.cssText += `outline:4px solid rgba(255,0,128,${Math.sqrt(Math.abs(v-1))}); border-radius: 0.4em !important;`;
}
});
return v; return v;
}""" }"""