2023-01-21 05:36:07 +00:00
|
|
|
|
|
|
|
function setupExtraNetworksForTab(tabname){
|
|
|
|
gradioApp().querySelector('#'+tabname+'_extra_tabs').classList.add('extra-networks')
|
|
|
|
|
2023-01-21 14:20:24 +00:00
|
|
|
var tabs = gradioApp().querySelector('#'+tabname+'_extra_tabs > div')
|
|
|
|
var search = gradioApp().querySelector('#'+tabname+'_extra_search textarea')
|
|
|
|
var refresh = gradioApp().getElementById(tabname+'_extra_refresh')
|
|
|
|
var close = gradioApp().getElementById(tabname+'_extra_close')
|
|
|
|
|
|
|
|
search.classList.add('search')
|
|
|
|
tabs.appendChild(search)
|
|
|
|
tabs.appendChild(refresh)
|
|
|
|
tabs.appendChild(close)
|
|
|
|
|
|
|
|
search.addEventListener("input", function(evt){
|
2023-01-22 07:30:55 +00:00
|
|
|
searchTerm = search.value.toLowerCase()
|
2023-01-21 14:20:24 +00:00
|
|
|
|
|
|
|
gradioApp().querySelectorAll('#'+tabname+'_extra_tabs div.card').forEach(function(elem){
|
2023-01-22 07:30:55 +00:00
|
|
|
text = elem.querySelector('.name').textContent.toLowerCase()
|
2023-01-21 14:20:24 +00:00
|
|
|
elem.style.display = text.indexOf(searchTerm) == -1 ? "none" : ""
|
|
|
|
})
|
|
|
|
});
|
2023-01-21 05:36:07 +00:00
|
|
|
}
|
|
|
|
|
2023-01-21 06:48:38 +00:00
|
|
|
var activePromptTextarea = {};
|
2023-01-21 05:36:07 +00:00
|
|
|
|
|
|
|
function setupExtraNetworks(){
|
|
|
|
setupExtraNetworksForTab('txt2img')
|
|
|
|
setupExtraNetworksForTab('img2img')
|
|
|
|
|
2023-01-21 06:48:38 +00:00
|
|
|
function registerPrompt(tabname, id){
|
2023-01-21 05:36:07 +00:00
|
|
|
var textarea = gradioApp().querySelector("#" + id + " > label > textarea");
|
|
|
|
|
2023-01-21 06:48:38 +00:00
|
|
|
if (! activePromptTextarea[tabname]){
|
|
|
|
activePromptTextarea[tabname] = textarea
|
2023-01-21 05:36:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
textarea.addEventListener("focus", function(){
|
2023-01-21 06:48:38 +00:00
|
|
|
activePromptTextarea[tabname] = textarea;
|
2023-01-21 05:36:07 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2023-01-21 06:48:38 +00:00
|
|
|
registerPrompt('txt2img', 'txt2img_prompt')
|
|
|
|
registerPrompt('txt2img', 'txt2img_neg_prompt')
|
|
|
|
registerPrompt('img2img', 'img2img_prompt')
|
|
|
|
registerPrompt('img2img', 'img2img_neg_prompt')
|
2023-01-21 05:36:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
onUiLoaded(setupExtraNetworks)
|
|
|
|
|
2023-01-21 06:48:38 +00:00
|
|
|
function cardClicked(tabname, textToAdd, allowNegativePrompt){
|
|
|
|
var textarea = allowNegativePrompt ? activePromptTextarea[tabname] : gradioApp().querySelector("#" + tabname + "_prompt > label > textarea")
|
2023-01-21 05:36:07 +00:00
|
|
|
|
|
|
|
textarea.value = textarea.value + " " + textToAdd
|
|
|
|
updateInput(textarea)
|
|
|
|
}
|
|
|
|
|
|
|
|
function saveCardPreview(event, tabname, filename){
|
2023-01-21 06:48:38 +00:00
|
|
|
var textarea = gradioApp().querySelector("#" + tabname + '_preview_filename > label > textarea')
|
|
|
|
var button = gradioApp().getElementById(tabname + '_save_preview')
|
2023-01-21 05:36:07 +00:00
|
|
|
|
|
|
|
textarea.value = filename
|
|
|
|
updateInput(textarea)
|
|
|
|
|
|
|
|
button.click()
|
|
|
|
|
|
|
|
event.stopPropagation()
|
|
|
|
event.preventDefault()
|
|
|
|
}
|