|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(function() { |
|
'use strict'; |
|
|
|
setTimeout(() => { |
|
const outputPathTxt2img1 = 'your/path/to/txt2img/output/folder'; |
|
const outputPathTxt2img2 = 'your/path/to/alternative/txt2img/output/folder'; |
|
|
|
const outputPathImg2img1 = 'your/path/to/img2img/output/folder'; |
|
const outputPathImg2img2 = 'your/path/to/alternative/img2img/output/folder'; |
|
|
|
const container = querySelectorAllShadows('.container')[0]; |
|
const txt2imgInput = querySelectorAllShadows('#setting_outdir_txt2img_samples textarea')[0]; |
|
const img2imgInput = querySelectorAllShadows('#setting_outdir_img2img_samples textarea')[0]; |
|
const saveBtn = querySelectorAllShadows('#tab_settings .gr-button-primary')[0]; |
|
|
|
const checked = txt2imgInput.value === outputPathTxt2img2 ? 'checked' : ''; |
|
|
|
console.log(container) |
|
console.log(txt2imgInput) |
|
console.log(saveBtn) |
|
$(container).prepend( ` |
|
<label class="toggle incognito"> |
|
<input class="toggle-checkbox" type="checkbox" ${checked}> |
|
<div class="toggle-switch"></div> |
|
<span class="toggle-label">Alternative directory</span> |
|
</label> |
|
` ); |
|
|
|
const incogintoEl = container.querySelector('.incognito .toggle-checkbox'); |
|
incogintoEl.addEventListener('change', (e) => { |
|
const targetEl = e.currentTarget; |
|
if (targetEl.checked) { |
|
console.log("Checkbox is checked.."); |
|
txt2imgInput.value = outputPathTxt2img2; |
|
img2imgInput.value = outputPathImg2img2; |
|
} else { |
|
console.log("Checkbox is not checked.."); |
|
txt2imgInput.value = outputPathTxt2img1; |
|
img2imgInput.value = outputPathImg2img1; |
|
} |
|
console.log(txt2imgInput) |
|
txt2imgInput.dispatchEvent(new Event("input", { bubbles: true })); |
|
img2imgInput.dispatchEvent(new Event("input", { bubbles: true })); |
|
}) |
|
console.log(incogintoEl) |
|
}, 1000) |
|
|
|
|
|
addStyle(` |
|
body { |
|
color:red; |
|
} |
|
.toggle { |
|
cursor: pointer; |
|
display: inline-block; |
|
margin-bottom: 2em; |
|
} |
|
|
|
.toggle-switch { |
|
display: inline-block; |
|
background: #ccc; |
|
border-radius: 16px; |
|
width: 58px; |
|
height: 32px; |
|
position: relative; |
|
vertical-align: middle; |
|
transition: background 0.25s; |
|
} |
|
.toggle-switch:before, .toggle-switch:after { |
|
content: ""; |
|
} |
|
.toggle-switch:before { |
|
display: block; |
|
background: linear-gradient(to bottom, #fff 0%, #eee 100%); |
|
border-radius: 50%; |
|
box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.25); |
|
width: 24px; |
|
height: 24px; |
|
position: absolute; |
|
top: 4px; |
|
left: 4px; |
|
transition: left 0.25s; |
|
} |
|
.toggle:hover .toggle-switch:before { |
|
background: linear-gradient(to bottom, #fff 0%, #fff 100%); |
|
box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.5); |
|
} |
|
.toggle-checkbox:checked + .toggle-switch { |
|
background: #56c080; |
|
} |
|
.toggle-checkbox:checked + .toggle-switch:before { |
|
left: 30px; |
|
} |
|
|
|
.toggle-checkbox { |
|
position: absolute; |
|
visibility: hidden; |
|
} |
|
|
|
.toggle-label { |
|
margin-left: 5px; |
|
position: relative; |
|
top: 2px; |
|
} |
|
`) |
|
|
|
function addStyle(styleText) { |
|
let s = document.createElement('style'); |
|
s.appendChild(document.createTextNode(styleText)); |
|
querySelectorAllShadows('.gradio-container')[0].appendChild(s); |
|
} |
|
|
|
function querySelectorAllShadows(selector, el = document.body) { |
|
|
|
const childShadows = Array.from(el.querySelectorAll('*')). |
|
map(el => el.shadowRoot).filter(Boolean); |
|
|
|
const childResults = childShadows.map(child => querySelectorAllShadows(selector, child)); |
|
|
|
|
|
const result = Array.from(el.querySelectorAll(selector)); |
|
return result.concat(childResults).flat(); |
|
} |
|
|
|
})(); |
|
|
|
|
|
|
|
|
|
|
|
|