Files
ComfyUI/custom_nodes/ComfyUI-KJNodes/web/js/contextmenu.js
jaidaken f09734b0ee
Some checks failed
Python Linting / Run Ruff (push) Has been cancelled
Python Linting / Run Pylint (push) Has been cancelled
Full Comfy CI Workflow Runs / test-stable (12.1, , linux, 3.10, [self-hosted Linux], stable) (push) Has been cancelled
Full Comfy CI Workflow Runs / test-stable (12.1, , linux, 3.11, [self-hosted Linux], stable) (push) Has been cancelled
Full Comfy CI Workflow Runs / test-stable (12.1, , linux, 3.12, [self-hosted Linux], stable) (push) Has been cancelled
Full Comfy CI Workflow Runs / test-unix-nightly (12.1, , linux, 3.11, [self-hosted Linux], nightly) (push) Has been cancelled
Execution Tests / test (macos-latest) (push) Has been cancelled
Execution Tests / test (ubuntu-latest) (push) Has been cancelled
Execution Tests / test (windows-latest) (push) Has been cancelled
Test server launches without errors / test (push) Has been cancelled
Unit Tests / test (macos-latest) (push) Has been cancelled
Unit Tests / test (ubuntu-latest) (push) Has been cancelled
Unit Tests / test (windows-2022) (push) Has been cancelled
Add custom nodes, Civitai loras (LFS), and vast.ai setup script
Includes 30 custom nodes committed directly, 7 Civitai-exclusive
loras stored via Git LFS, and a setup script that installs all
dependencies and downloads HuggingFace-hosted models on vast.ai.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-09 00:56:42 +00:00

176 lines
4.8 KiB
JavaScript

const { app } = window.comfyAPI.app;
// Adds context menu entries, code partly from pyssssscustom-scripts
function addMenuHandler(nodeType, cb) {
const getOpts = nodeType.prototype.getExtraMenuOptions;
nodeType.prototype.getExtraMenuOptions = function () {
const r = getOpts.apply(this, arguments);
cb.apply(this, arguments);
return r;
};
}
function addNode(name, nextTo, options) {
console.log("name:", name);
console.log("nextTo:", nextTo);
options = { side: "left", select: true, shiftY: 0, shiftX: 0, ...(options || {}) };
const node = LiteGraph.createNode(name);
app.graph.add(node);
node.pos = [
options.side === "left" ? nextTo.pos[0] - (node.size[0] + options.offset): nextTo.pos[0] + nextTo.size[0] + options.offset,
nextTo.pos[1] + options.shiftY,
];
// Automatically connect nodes
if (options.side === "left") {
// New node on left: connect new node's output to nextTo's first available input
if (node.outputs && node.outputs.length > 0 && nextTo.inputs && nextTo.inputs.length > 0) {
for (let i = 0; i < nextTo.inputs.length; i++) {
if (!nextTo.inputs[i].link) {
node.connect(0, nextTo, i);
break;
}
}
}
} else {
// New node on right: connect nextTo's output to new node's first available input
if (nextTo.outputs && nextTo.outputs.length > 0 && node.inputs && node.inputs.length > 0) {
for (let i = 0; i < node.inputs.length; i++) {
if (!node.inputs[i].link) {
nextTo.connect(0, node, i);
break;
}
}
}
}
if (options.select) {
app.canvas.selectNode(node, false);
}
return node;
}
app.registerExtension({
name: "KJNodesContextmenu",
async beforeRegisterNodeDef(nodeType, nodeData, app) {
if (nodeData.input && nodeData.input.required) {
addMenuHandler(nodeType, function (_, options) {
options.unshift(
{
content: "Add GetNode",
callback: () => {addNode("GetNode", this, { side:"left", offset: 30});}
},
{
content: "Add SetNode",
callback: () => {addNode("SetNode", this, { side:"right", offset: 30 });}
},
{
content: "Add PreviewAsTextNode",
callback: () => {addNode("PreviewAny", this, { side:"right", offset: 30 });
},
});
});
}
},
async setup(app) {
const updateSlots = (value) => {
const valuesToAddToIn = ["GetNode"];
const valuesToAddToOut = ["SetNode"];
// Remove entries if they exist
for (const arr of Object.values(LiteGraph.slot_types_default_in)) {
for (const valueToAdd of valuesToAddToIn) {
const idx = arr.indexOf(valueToAdd);
if (idx !== -1) {
arr.splice(idx, 1);
}
}
}
for (const arr of Object.values(LiteGraph.slot_types_default_out)) {
for (const valueToAdd of valuesToAddToOut) {
const idx = arr.indexOf(valueToAdd);
if (idx !== -1) {
arr.splice(idx, 1);
}
}
}
if (value!="disabled") {
for (const arr of Object.values(LiteGraph.slot_types_default_in)) {
for (const valueToAdd of valuesToAddToIn) {
const idx = arr.indexOf(valueToAdd);
if (idx !== -1) {
arr.splice(idx, 1);
}
if (value === "top") {
arr.unshift(valueToAdd);
} else {
arr.push(valueToAdd);
}
}
}
for (const arr of Object.values(LiteGraph.slot_types_default_out)) {
for (const valueToAdd of valuesToAddToOut) {
const idx = arr.indexOf(valueToAdd);
if (idx !== -1) {
arr.splice(idx, 1);
}
if (value === "top") {
arr.unshift(valueToAdd);
} else {
arr.push(valueToAdd);
}
}
}
}
};
app.ui.settings.addSetting({
id: "KJNodes.SetGetMenu",
name: "KJNodes: Make Set/Get -nodes defaults",
tooltip: 'Adds Set/Get nodes to the top or bottom of the list of available node suggestions.',
options: ['disabled', 'top', 'bottom'],
defaultValue: 'disabled',
type: "combo",
onChange: updateSlots,
});
app.ui.settings.addSetting({
id: "KJNodes.MiddleClickDefault",
name: "KJNodes: Middle click default node adding",
defaultValue: false,
type: "boolean",
onChange: (value) => {
LiteGraph.middle_click_slot_add_default_node = value;
},
});
app.ui.settings.addSetting({
id: "KJNodes.nodeAutoColor",
name: "KJNodes: Automatically set node colors",
type: "boolean",
defaultValue: true,
});
app.ui.settings.addSetting({
id: "KJNodes.helpPopup",
name: "KJNodes: Help popups",
defaultValue: true,
type: "boolean",
});
app.ui.settings.addSetting({
id: "KJNodes.disablePrefix",
name: "KJNodes: Disable automatic Set_ and Get_ prefix",
defaultValue: true,
type: "boolean",
});
app.ui.settings.addSetting({
id: "KJNodes.browserStatus",
name: "KJNodes: 🟢 Stoplight browser status icon 🔴",
defaultValue: false,
type: "boolean",
});
}
});