Files
GenorTG-ComfyUI-PromptForge/web/promptforge_action.js
T
2026-11-09 13:58:39 +01:00

37 lines
1.3 KiB
JavaScript

import { app } from "../../scripts/app.js";
const NODE = "PROMPTFORGE_ImageAction";
const CATEGORIES = {
"SFW - portrait and expression": null,
};
app.registerExtension({
name: "PromptForge.ImageAction",
async beforeRegisterNodeDef(nodeType, nodeData) {
if (nodeData.name !== NODE) return;
const onCreated = nodeType.prototype.onNodeCreated;
nodeType.prototype.onNodeCreated = function () {
onCreated?.apply(this, arguments);
const widget = (name) => this.widgets.find((item) => item.name === name);
const category = widget("category");
const action = widget("action");
if (!category || !action) return;
const all = [...action.options.values];
const groups = {};
for (const label of all) {
const prefix = label.split(" · ")[0];
(groups[prefix] ||= []).push(label);
}
const apply = () => {
const wanted = (groups[category.value] || []);
action.options.values = wanted.length ? wanted : all;
if (!wanted.includes(action.value)) action.value = action.options.values[0];
this.setDirtyCanvas(true, true);
};
const callback = category.callback;
category.callback = function () { callback?.apply(this, arguments); apply(); };
apply();
};
},
});