From e4c09508093e5d675a80a74723c67cccdb537b4b Mon Sep 17 00:00:00 2001 From: DigitalIO Date: Sun, 17 Dec 2023 22:46:47 -0500 Subject: [PATCH] Title will now stay updated with the current prompt --- js/StableWildcard.js | 40 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 38 insertions(+), 2 deletions(-) diff --git a/js/StableWildcard.js b/js/StableWildcard.js index e6524d4..05791e0 100644 --- a/js/StableWildcard.js +++ b/js/StableWildcard.js @@ -19,7 +19,8 @@ # SOFTWARE. #*/ -import { app } from "../../../scripts/app.js"; +import { app } from "../../scripts/app.js"; +import { api } from "../../scripts/api.js"; /** Change the title for the text area to include the loaded result @@ -37,6 +38,36 @@ function loadStableWildcardNode(node, app) { node.widgets[0].element.title = wildcardData[node.id]; } +/** + Attach to the textarea and seed and update the title after every change +*/ +function stableWildcardNodeCreated(node, app) { + async function updateTitle(e) { + + const promptValue = node.widgets[0].element.value; + const seedValue = node.widgets[1].value; + + // Get the resulting string from the server + const response = await api.fetchApi(`/stable-wildcards/process`, { + method: 'POST', + headers: { 'Content-Type': 'application/json' }, + body: JSON.stringify({prompt: promptValue, seed: seedValue}) + }); + + const data = await response.json(); + + node.widgets[0].element.title = data['prompt']; + } + + // Add event listeners + node.widgets[0].element.addEventListener( + 'change', + updateTitle, + false + ); + +} + // Create the Stable Wildcard extension const StableWildcardsExtension = { name: 'StableWildcards', @@ -44,8 +75,13 @@ const StableWildcardsExtension = { if (node.type !== "Stable Wildcards") { return; } - loadStableWildcardNode(node, app); + }, + nodeCreated(node, app) { + if (node.comfyClass !== "Stable Wildcards") { + return; + } + stableWildcardNodeCreated(node, app); } }