diff --git a/public/scripts/extensions/stable-diffusion/index.js b/public/scripts/extensions/stable-diffusion/index.js index 24eb935dc..dd9c193b8 100644 --- a/public/scripts/extensions/stable-diffusion/index.js +++ b/public/scripts/extensions/stable-diffusion/index.js @@ -4058,7 +4058,35 @@ jQuery(async () => { await onSourceChange(); return extension_settings.sd.source; }, - })) + })); + + SlashCommandParser.addCommandObject(SlashCommand.fromProps({ + name: 'imagine-style', + aliases: ['sd-style', 'img-style'], + returns: 'a name of the current style', + unnamedArgumentList: [ + SlashCommandArgument.fromProps({ + description: 'style name', + typeList: [ARGUMENT_TYPE.STRING], + isRequired: false, + forceEnum: true, + enumProvider: () => Array.from(document.querySelectorAll('#sd_style > [value]')).map(x => new SlashCommandEnumValue(x.getAttribute('value'), x.textContent)), + }), + ], + helpString: 'If an argument is provided, change the style of the image generation, e.g. /imagine-style MyStyle. Returns the current style.', + callback: async (_args, name) => { + if (!name) { + return extension_settings.sd.style; + } + const option = document.querySelector(`#sd_style [value="${name}"]`); + if (!(option instanceof HTMLOptionElement)) { + throw new Error('Could not find the style option in the dropdown.'); + } + option.selected = true; + onStyleSelect(); + return extension_settings.sd.style; + }, + })); SlashCommandParser.addCommandObject(SlashCommand.fromProps({ name: 'imagine-comfy-workflow',