diff --git a/LICENSE b/LICENSE index b0340f4..e1fd273 100644 --- a/LICENSE +++ b/LICENSE @@ -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 diff --git a/README.md b/README.md index 55b54fc..b743a62 100644 --- a/README.md +++ b/README.md @@ -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`. \ No newline at end of file diff --git a/javascript/prompt_format.js b/javascript/prompt_format.js new file mode 100644 index 0000000..14a1bd9 --- /dev/null +++ b/javascript/prompt_format.js @@ -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) + } + }) + +}) \ No newline at end of file