From 5d1b2272173868c4151a1ffe326f201a9beb814e Mon Sep 17 00:00:00 2001 From: newtextdoc1111 Date: Sat, 10 May 2025 00:35:47 +0900 Subject: [PATCH] Change if statement block --- web/js/main.js | 40 ++++++++++++++++++++-------------------- web/js/settings.js | 2 +- 2 files changed, 21 insertions(+), 21 deletions(-) diff --git a/web/js/main.js b/web/js/main.js index 07bcdd4..414d8b6 100644 --- a/web/js/main.js +++ b/web/js/main.js @@ -50,30 +50,30 @@ function initializeEventHandlers() { }; } - // Fallback and for dynamically added elements not caught by widget override: MutationObserver - const targetSelectors = [ - '.comfy-multiline-input', - // Add other selectors if needed - ]; + if (settingValues._useFallbackAttachmentForEventListener) { + // Fallback and for dynamically added elements not caught by widget override: MutationObserver + const targetSelectors = [ + '.comfy-multiline-input', + // Add other selectors if needed + ]; - const observer = new MutationObserver((mutations) => { - mutations.forEach((mutation) => { - mutation.addedNodes.forEach((node) => { - if (node.nodeType === Node.ELEMENT_NODE) { - targetSelectors.forEach(selector => { - // Check if the added node itself matches or contains matching elements - if (node.matches(selector)) { - attachListeners(node); - } else { - node.querySelectorAll(selector).forEach(attachListeners); - } - }); - } + const observer = new MutationObserver((mutations) => { + mutations.forEach((mutation) => { + mutation.addedNodes.forEach((node) => { + if (node.nodeType === Node.ELEMENT_NODE) { + targetSelectors.forEach(selector => { + // Check if the added node itself matches or contains matching elements + if (node.matches(selector)) { + attachListeners(node); + } else { + node.querySelectorAll(selector).forEach(attachListeners); + } + }); + } + }); }); }); - }); - if (settingValues._useFallbackAttachmentForEventListener) { // Initial scan for existing elements targetSelectors.forEach(selector => { document.querySelectorAll(selector).forEach(attachListeners); diff --git a/web/js/settings.js b/web/js/settings.js index 2629dc0..404edd9 100644 --- a/web/js/settings.js +++ b/web/js/settings.js @@ -11,7 +11,7 @@ export const settingValues = { // Internal logic settings - _useFallbackAttachmentForEventListener: false, // Fallback to attach event listener if not using jQuery + _useFallbackAttachmentForEventListener: false, // Fallback to attach event listener when somthing goes wrong // Debugging settings (use internally) _hideWhenOutofFocus: false, // Hide UI when the input is out of focus