// AI Disclosure: Code comments were generated with AI import { app } from "../../scripts/app.js"; app.registerExtension({ name: "ComfyUI.SimpleFString", async beforeRegisterNodeDef(nodeType, nodeData, app) { if (nodeData.name === "SimpleFStringNode") { // This function adds the "Add Input" and "Remove Input" options // to the right-click context menu of the node. const getExtraMenuOptions = nodeType.prototype.getExtraMenuOptions; nodeType.prototype.getExtraMenuOptions = function(_, options) { // Run the original menu logic first (if any) if (getExtraMenuOptions) { getExtraMenuOptions.apply(this, arguments); } // Add "Add Input" option options.unshift({ content: "Add Input (Variable)", callback: () => { // Ask the user for the variable name (e.g., "my_image") const name = prompt("Enter input name (used in f-string as {name}):"); if (name) { // Verify duplicates const exists = this.findInputSlot(name); if (exists !== -1) { alert("Input with that name already exists!"); return; } // 1st arg: name, 2nd arg: type ("*" = wildcard), 3rd arg: shape this.addInput(name, "*"); // Tell ComfyUI the graph changed so it saves the new slot this.setDirtyCanvas(true, true); } } }); // Add "Remove Input" option options.unshift({ content: "Remove Last Input", callback: () => { // Check if we have optional inputs to remove // (We don't want to remove the required "template" input) if (this.inputs && this.inputs.length > 1) { // Remove the last input in the array this.removeInput(this.inputs.length - 1); } } }); }; } }, });