From 9af1c4a4c2a9ea8ff5a23155d6528c9221561b73 Mon Sep 17 00:00:00 2001 From: Emil <7682404+em411@users.noreply.github.com> Date: Sun, 1 Oct 2023 22:03:58 +0200 Subject: [PATCH] add support for SD.Next --- javascript/prompt_format.js | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/javascript/prompt_format.js b/javascript/prompt_format.js index 8c4b6ae..ba38b16 100644 --- a/javascript/prompt_format.js +++ b/javascript/prompt_format.js @@ -59,7 +59,14 @@ class LeFormatter { // ===== Main Format Logics ===== static formatPipeline(id, dedupe, removeUnderscore, autoRefresh) { - const textArea = gradioApp().getElementById(id).querySelector('textarea') + const textAreaElement = gradioApp().getElementById(id); + + if (!textAreaElement) { + console.log(`Could not find element with id ${id}`); + return; + } + + const textArea = textAreaElement.querySelector('textarea') let lines = textArea.value.split('\n') @@ -170,7 +177,14 @@ class LeFormatter { } static injectTagShift(id) { - const textarea = gradioApp().getElementById(id).querySelector('textarea') + const textAreaElement = gradioApp().getElementById(id); + + if (!textAreaElement) { + console.log(`Could not find element with id ${id}`); + return; + } + + const textarea = textAreaElement.querySelector('textarea') textarea.addEventListener('wheel', (event) => { if (event.shiftKey) { @@ -236,7 +250,14 @@ class LeFormatter { } static injectBracketEscape(id) { - const textarea = gradioApp().getElementById(id).querySelector('textarea') + const textAreaElement = gradioApp().getElementById(id); + + if (!textAreaElement) { + console.log(`Could not find element with id ${id}`); + return; + } + + const textarea = textAreaElement.querySelector('textarea') textarea.addEventListener('keydown', (event) => { if (event.ctrlKey && event.key === '\\') { @@ -286,7 +307,7 @@ onUiLoaded(async () => { const manualBtn = LeFormatter.manualButton({ onClick: () => { const ids = ['txt2img_prompt', 'txt2img_neg_prompt', 'img2img_prompt', 'img2img_neg_prompt', 'hires_prompt', 'hires_neg_prompt'] - ids.forEach((id) => formatPipeline(id, dedupe, removeUnderscore, true)) + ids.forEach((id) => LeFormatter.formatPipeline(id, dedupe, removeUnderscore, true)) } })