2023-01-21 08:36:07 +03:00
|
|
|
|
|
|
|
function setupExtraNetworksForTab(tabname){
|
|
|
|
gradioApp().querySelector('#'+tabname+'_extra_tabs').classList.add('extra-networks')
|
|
|
|
|
2023-01-21 17:20:24 +03:00
|
|
|
var tabs = gradioApp().querySelector('#'+tabname+'_extra_tabs > div')
|
|
|
|
var search = gradioApp().querySelector('#'+tabname+'_extra_search textarea')
|
|
|
|
var refresh = gradioApp().getElementById(tabname+'_extra_refresh')
|
|
|
|
|
|
|
|
search.classList.add('search')
|
|
|
|
tabs.appendChild(search)
|
|
|
|
tabs.appendChild(refresh)
|
|
|
|
|
|
|
|
search.addEventListener("input", function(evt){
|
2023-01-22 10:30:55 +03:00
|
|
|
searchTerm = search.value.toLowerCase()
|
2023-01-21 17:20:24 +03:00
|
|
|
|
|
|
|
gradioApp().querySelectorAll('#'+tabname+'_extra_tabs div.card').forEach(function(elem){
|
2023-01-29 10:20:19 +03:00
|
|
|
text = elem.querySelector('.name').textContent.toLowerCase() + " " + elem.querySelector('.search_term').textContent.toLowerCase()
|
2023-01-21 17:20:24 +03:00
|
|
|
elem.style.display = text.indexOf(searchTerm) == -1 ? "none" : ""
|
|
|
|
})
|
|
|
|
});
|
2023-01-21 08:36:07 +03:00
|
|
|
}
|
|
|
|
|
2023-01-21 09:48:38 +03:00
|
|
|
var activePromptTextarea = {};
|
2023-01-21 08:36:07 +03:00
|
|
|
|
|
|
|
function setupExtraNetworks(){
|
|
|
|
setupExtraNetworksForTab('txt2img')
|
|
|
|
setupExtraNetworksForTab('img2img')
|
|
|
|
|
2023-01-21 09:48:38 +03:00
|
|
|
function registerPrompt(tabname, id){
|
2023-01-21 08:36:07 +03:00
|
|
|
var textarea = gradioApp().querySelector("#" + id + " > label > textarea");
|
|
|
|
|
2023-01-21 09:48:38 +03:00
|
|
|
if (! activePromptTextarea[tabname]){
|
|
|
|
activePromptTextarea[tabname] = textarea
|
2023-01-21 08:36:07 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
textarea.addEventListener("focus", function(){
|
2023-01-21 09:48:38 +03:00
|
|
|
activePromptTextarea[tabname] = textarea;
|
2023-01-21 08:36:07 +03:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2023-01-21 09:48:38 +03:00
|
|
|
registerPrompt('txt2img', 'txt2img_prompt')
|
|
|
|
registerPrompt('txt2img', 'txt2img_neg_prompt')
|
|
|
|
registerPrompt('img2img', 'img2img_prompt')
|
|
|
|
registerPrompt('img2img', 'img2img_neg_prompt')
|
2023-01-21 08:36:07 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
onUiLoaded(setupExtraNetworks)
|
|
|
|
|
2023-01-28 23:31:48 +03:00
|
|
|
var re_extranet = /<([^:]+:[^:]+):[\d\.]+>/;
|
|
|
|
var re_extranet_g = /\s+<([^:]+:[^:]+):[\d\.]+>/g;
|
|
|
|
|
|
|
|
function tryToRemoveExtraNetworkFromPrompt(textarea, text){
|
|
|
|
var m = text.match(re_extranet)
|
|
|
|
if(! m) return false
|
|
|
|
|
|
|
|
var partToSearch = m[1]
|
|
|
|
var replaced = false
|
|
|
|
var newTextareaText = textarea.value.replaceAll(re_extranet_g, function(found, index){
|
|
|
|
m = found.match(re_extranet);
|
|
|
|
if(m[1] == partToSearch){
|
|
|
|
replaced = true;
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
return found;
|
|
|
|
})
|
|
|
|
|
|
|
|
if(replaced){
|
|
|
|
textarea.value = newTextareaText
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2023-01-21 09:48:38 +03:00
|
|
|
function cardClicked(tabname, textToAdd, allowNegativePrompt){
|
|
|
|
var textarea = allowNegativePrompt ? activePromptTextarea[tabname] : gradioApp().querySelector("#" + tabname + "_prompt > label > textarea")
|
2023-01-21 08:36:07 +03:00
|
|
|
|
2023-01-28 23:31:48 +03:00
|
|
|
if(! tryToRemoveExtraNetworkFromPrompt(textarea, textToAdd)){
|
|
|
|
textarea.value = textarea.value + " " + textToAdd
|
|
|
|
}
|
|
|
|
|
2023-01-21 08:36:07 +03:00
|
|
|
updateInput(textarea)
|
|
|
|
}
|
|
|
|
|
|
|
|
function saveCardPreview(event, tabname, filename){
|
2023-01-21 09:48:38 +03:00
|
|
|
var textarea = gradioApp().querySelector("#" + tabname + '_preview_filename > label > textarea')
|
|
|
|
var button = gradioApp().getElementById(tabname + '_save_preview')
|
2023-01-21 08:36:07 +03:00
|
|
|
|
|
|
|
textarea.value = filename
|
|
|
|
updateInput(textarea)
|
|
|
|
|
|
|
|
button.click()
|
|
|
|
|
|
|
|
event.stopPropagation()
|
|
|
|
event.preventDefault()
|
|
|
|
}
|
2023-01-29 11:34:58 +03:00
|
|
|
|
|
|
|
function extraNetworksSearchButton(tabs_id, event){
|
|
|
|
searchTextarea = gradioApp().querySelector("#" + tabs_id + ' > div > textarea')
|
|
|
|
button = event.target
|
|
|
|
text = button.classList.contains("search-all") ? "" : button.textContent.trim()
|
|
|
|
|
|
|
|
searchTextarea.value = text
|
|
|
|
updateInput(searchTextarea)
|
|
|
|
}
|