-
Notifications
You must be signed in to change notification settings - Fork 37
/
viewText.js
42 lines (33 loc) · 1.55 KB
/
viewText.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import { app } from "../../../scripts/app.js";
import { ComfyWidgets } from "../../../scripts/widgets.js";
app.registerExtension({
name: "n.ViewText",
async beforeRegisterNodeDef(nodeType, nodeData, app) {
if (nodeData.name === "ViewText") {
console.warn("ViewText");
const onExecuted = nodeType.prototype.onExecuted;
nodeType.prototype.onExecuted = function (message) {
if (this.widgets) {
for (let i = 1; i < this.widgets.length; i++) {
this.widgets[i].onRemove?.();
}
this.widgets.length = 1;
}
// Call the original onExecuted method if it exists.
onExecuted?.apply(this, arguments);
// Check if the "text" widget already exists.
let textWidget = this.widgets.find(w => w.name === "new_text");
if (!textWidget) {
// If the "text" widget does not exist, create it.
textWidget = ComfyWidgets["STRING"](this, "new_text", ["STRING", { multiline: true }], app).widget;
}
// Generate a random number and set it as the value of the "text" widget.
textWidget.inputEl.readOnly = true;
textWidget.inputEl.style.opacity = 0.6;
textWidget.value = message["text"].join("");
// change color of the widget
console.log(message)
};
}
},
});