Put an end to all the tab shenanigans
parent
f8ff9bcab3
commit
27663f3366
|
|
@ -1,31 +1,26 @@
|
|||
function setupNPW() {
|
||||
fixAccordion();
|
||||
fixInputs();
|
||||
fixAccordion('tab_txt2img');
|
||||
fixAccordion('tab_img2img');
|
||||
fixInputs('tab_txt2img');
|
||||
fixInputs('tab_img2img');
|
||||
}
|
||||
|
||||
function fixInputs() {
|
||||
const npwSlider_t2i = document.querySelector("#tab_txt2img #npw-slider");
|
||||
const npwSlider_i2i = document.querySelector("#tab_img2img #npw-slider");
|
||||
function fixInputs(tab) {
|
||||
const npwSlider = document.querySelector(`#${tab} #npw-slider`);
|
||||
|
||||
npwSlider_t2i.querySelector('.head').remove();
|
||||
npwSlider_i2i.querySelector('.head').remove();
|
||||
npwSlider.querySelector('.head').remove();
|
||||
|
||||
const newSpan = document.createElement("span");
|
||||
newSpan.innerHTML = "Negative Prompt Weight";
|
||||
const ancestor_t2i = npwSlider_t2i.parentNode.parentNode.parentNode;
|
||||
ancestor_t2i.insertBefore(newSpan, ancestor_t2i.firstChild);
|
||||
const ancestor_i2i = npwSlider_i2i.parentNode.parentNode.parentNode;
|
||||
ancestor_i2i.insertBefore(newSpan.cloneNode(true), ancestor_i2i.firstChild);
|
||||
const ancestor = npwSlider.parentNode.parentNode.parentNode;
|
||||
ancestor.insertBefore(newSpan, ancestor.firstChild);
|
||||
|
||||
document.querySelector('#tab_txt2img #npw-number input[type="number"]').setAttribute("step", "0.01");
|
||||
document.querySelector('#tab_img2img #npw-number input[type="number"]').setAttribute("step", "0.01");
|
||||
document.querySelector(`#${tab} #npw-number input[type="number"]`).setAttribute("step", "0.01");
|
||||
}
|
||||
|
||||
function fixAccordion() {
|
||||
document.querySelector('#tab_txt2img #npw .icon').remove();
|
||||
document.querySelector('#tab_img2img #npw .icon').remove();
|
||||
document.querySelector('#tab_txt2img #npw .open').remove();
|
||||
document.querySelector('#tab_img2img #npw .open').remove();
|
||||
function fixAccordion(tab) {
|
||||
document.querySelector(`#${tab} #npw .icon`).remove();
|
||||
document.querySelector(`#${tab} #npw .open`).remove();
|
||||
}
|
||||
|
||||
onUiLoaded(setupNPW);
|
||||
|
|
|
|||
|
|
@ -26,12 +26,14 @@ class Script(scripts.Script):
|
|||
reset_but = gr.Button(value='✕', elem_id='npw-x').style(full_width=False, size='sm')
|
||||
|
||||
js = """(v) => {
|
||||
let t=document.querySelector('#txt2img_negative_token_counter'),
|
||||
i=document.querySelector('#img2img_negative_token_counter');
|
||||
t.style.cssText+=`outline:4px solid rgba(255,0,128,${Math.sqrt(Math.abs(v-1))}); border-radius: 0.4em !important;`
|
||||
i.style.cssText+=`outline:4px solid rgba(255,0,128,${Math.sqrt(Math.abs(v-1))}); border-radius: 0.4em !important;`
|
||||
return v;
|
||||
}"""
|
||||
['#txt2img_negative_token_counter', '#img2img_negative_token_counter'].forEach((selector, index) => {
|
||||
const element = document.querySelector(selector);
|
||||
if (document.querySelector(`#tab_${index ? 'img2img' : 'txt2img'}`).style.display === 'block') {
|
||||
element.style.cssText += `outline:4px solid rgba(255,0,128,${Math.sqrt(Math.abs(v-1))}); border-radius: 0.4em !important;`;
|
||||
}
|
||||
});
|
||||
return v;
|
||||
}"""
|
||||
|
||||
weight_input.change(None, [weight_input], weight_input_slider, _js=js)
|
||||
weight_input_slider.release(None, weight_input_slider, weight_input, _js="(x) => x")
|
||||
|
|
|
|||
Loading…
Reference in New Issue