新規作成

This commit is contained in:
るみなー先生
2026-05-12 21:25:19 +09:00
commit d110477e9d
4 changed files with 263 additions and 0 deletions
+38
View File
@@ -0,0 +1,38 @@
import { app } from "../../scripts/app.js";
const EXTENSION_NAME = "ruminar.PromptRandomChoice";
const NODE_NAME = "PromptRandomChoice";
function shorten(text, maxLength = 40) {
const value = String(text ?? "");
if (value.length <= maxLength) {
return value;
}
return value.slice(0, maxLength - 3) + "...";
}
app.registerExtension({
name: EXTENSION_NAME,
beforeRegisterNodeDef(nodeType, nodeData) {
if (String(nodeData?.name ?? "") !== NODE_NAME) {
return;
}
const originalOnExecuted = nodeType.prototype.onExecuted;
nodeType.prototype.onExecuted = function (message) {
originalOnExecuted?.apply(this, arguments);
const selected = message?.selected_text?.[0] ?? "";
if (selected) {
this.title = `Choice: ${shorten(selected)}`;
} else {
this.title = "Prompt Random Choice";
}
this.setDirtyCanvas?.(true, true);
app.graph?.setDirtyCanvas?.(true, true);
};
},
});