MCPcopy Create free account
hub / github.com/WainWong/ComfyUI-Loop-image / beforeRegisterNodeDef

Function beforeRegisterNodeDef

web/node/dynamicnode.js:10–107  ·  view source on GitHub ↗
(nodeType, nodeData, app)

Source from the content-addressed store, hash-verified

8app.registerExtension({
9 name: 'CyberEveLoop.LoopIndexSwitch',
10 async beforeRegisterNodeDef(nodeType, nodeData, app) {
11 // 添加调试信息
12 console.log("Registering extension for:", nodeData.name);
13 console.log("Looking for:", _ID);
14 if (nodeData.name !== _ID) {
15 return;
16 }
17
18 // 添加右键菜单选项
19 const onGetExtraMenuOptions = nodeType.prototype.getExtraMenuOptions;
20 nodeType.prototype.getExtraMenuOptions = function(_, options) {
21 if (onGetExtraMenuOptions) {
22 onGetExtraMenuOptions.apply(this, arguments);
23 }
24
25 // 添加输入槽
26 options.push({
27 content: "Add Loop Input",
28 callback: () => {
29 // 弹出对话框让用户输入循环次数
30 const number = prompt("Enter loop iteration number (0-99):", "0");
31 if (number === null || isNaN(number)) {
32 return;
33 }
34
35 const num = parseInt(number);
36 if (num < 0 || num >= MAX_INPUTS) {
37 alert(`Please enter a number between 0 and ${MAX_INPUTS-1}`);
38 return;
39 }
40
41 const slotName = `${_PREFIX}${num}`;
42
43 // 检查是否已存在该输入槽
44 if (this.inputs.find(input => input.name === slotName)) {
45 alert(`Input for iteration ${num} already exists!`);
46 return;
47 }
48
49 // 添加新的输入槽
50 this.addInput(slotName, _TYPE);
51 this.graph.setDirtyCanvas(true);
52 }
53 });
54
55 // 删除输入槽子菜单
56 const valueInputs = this.inputs.filter(input =>
57 input.name.startsWith(_PREFIX)
58 );
59
60 if (valueInputs.length > 0) {
61 const removeOptions = valueInputs.map(input => ({
62 content: `Remove iteration ${input.name.substring(_PREFIX.length)}`,
63 callback: () => {
64 const index = this.inputs.findIndex(i => i.name === input.name);
65 if (index !== -1) {
66 this.removeInput(index);
67 this.graph.setDirtyCanvas(true);

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected