pull/4/head
Haoming 2023-05-04 22:26:36 +08:00
parent 9988e25168
commit c634fba4a0
3 changed files with 59 additions and 3 deletions

View File

@ -1,6 +1,6 @@
MIT License
Copyright (c) 2023 Haoming
Copyright (c) 2023
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal

View File

@ -1,2 +1,6 @@
# sd-webui-promptformat
An Extention for Automatic1111 Webui that helps clean up prompts
# SD Webui Prompt Format
This is an Extension for the [Automatic1111 Webui](https://github.com/AUTOMATIC1111/stable-diffusion-webui), which aims to help formatting prompts upon generation.
### What This Does?
- Sometimes when you are typing too fast or are copying tags from all over the places, you end up with duplicated spaces or commas. This simple script helps removing them whenever you click **Generate**.
- Works for both `txt2img` and `img2img`.

View File

@ -0,0 +1,52 @@
class LeFormatter {
static injectTxt2ImgButton({
onClick
}) {
const t2i_button = gradioApp().getElementById('txt2img_generate')
t2i_button.addEventListener('click', onClick)
}
static injectImg2ImgButton({
onClick
}) {
const i2i_button = gradioApp().getElementById('img2img_generate')
i2i_button.addEventListener('click', onClick)
}
}
onUiLoaded(async () => {
LeFormatter.injectTxt2ImgButton({
onClick: () => {
const idP = 'txt2img_prompt'
const textareaP = gradioApp().getElementById(idP).querySelector('textarea')
const tagsP = textareaP.value.split(',').map(word => word.trim()).filter(word => word !== '');
textareaP.value = tagsP.join(', ');
updateInput(textareaP)
const idN = 'txt2img_neg_prompt'
const textareaN = gradioApp().getElementById(idN).querySelector('textarea')
const tagsN = textareaN.value.split(',').map(word => word.trim()).filter(word => word !== '');
textareaN.value = tagsN.join(', ');
updateInput(textareaN)
}
})
LeFormatter.injectImg2ImgButton({
onClick: () => {
const idP = 'img2img_prompt'
const textareaP = gradioApp().getElementById(idP).querySelector('textarea')
const tagsP = textareaP.value.split(',').map(word => word.trim()).filter(word => word !== '');
textareaP.value = tagsP.join(', ');
updateInput(textareaP)
const idN = 'img2img_neg_prompt'
const textareaN = gradioApp().getElementById(idN).querySelector('textarea')
const tagsN = textareaN.value.split(',').map(word => word.trim()).filter(word => word !== '');
textareaN.value = tagsN.join(', ');
updateInput(textareaN)
}
})
})