From 73853a60ff48a83fff1f71c6f7b26104ca75123d Mon Sep 17 00:00:00 2001 From: EmmanuelMr18 Date: Tue, 7 Jan 2025 23:49:03 -0600 Subject: [PATCH] feat: inject buttons in the right position of the comfyui menu --- web-plugin/index.js | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/web-plugin/index.js b/web-plugin/index.js index c2a5337..71ec125 100644 --- a/web-plugin/index.js +++ b/web-plugin/index.js @@ -742,6 +742,8 @@ const ext = { sendEventToCD("cd_plugin_onQueuePrompt", prompt); } else if (message.type === "configure_queue_buttons") { addQueueButtons(message.data); + } else if (message.type === "configure_menu_right_buttons") { + addMenuRightButtons(message.data); } else if (message.type === "get_prompt") { const prompt = await app.graphToPrompt(); sendEventToCD("cd_plugin_onGetPrompt", prompt); @@ -2115,3 +2117,41 @@ function addQueueButtons(buttonConfigs = DEFAULT_BUTTONS) { queueButtonGroup.appendChild(button); }); } + +// Function to add butons to the menu right +function addMenuRightButtons(buttonConfigs) { + const menuRightButtons = document.querySelector('.comfyui-menu-right') + + if (!menuRightButtons) return + + // Remove any existing CD buttons + const existingButtons = document.querySelectorAll('.comfyui-menu-right [id^="cd-button-"]') + for (const button of existingButtons) { + button.remove() + } + + if (!menuRightButtons) return + + for (const config of buttonConfigs) { + const button = createMenuRightButton(config) + menuRightButtons.appendChild(button) + } +} + +function createMenuRightButton(config) { + const button = document.createElement('button') + button.id = `cd-button-${config.id}` + button.className = 'p-button p-component p-button-secondary p-button-md' + button.innerHTML = ` + + ${config.label} + ` + button.onclick = () => { + const eventData = typeof config.eventData === 'function' ? + config.eventData() : + config.eventData || {} + sendEventToCD(config.event, eventData) + } + button.setAttribute('data-pd-tooltip', config.tooltip) + return button +} \ No newline at end of file