File size: 2,228 Bytes
f2dbf59
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
43
44
45
46
47
48
49
50
51
52
53
import { app } from "../../scripts/app.js";
import { ComfyWidgets } from "../../scripts/widgets.js";

app.registerExtension({
    name: "fnodes.DisplayAny",
    async beforeRegisterNodeDef(nodeType, nodeData, app) {
        if (!nodeData?.category?.startsWith("fnodes")) {
            return;
        }
        
        switch (nodeData.name) {
            case "DisplayAny-":
                const onExecutedDisplayAny = nodeType.prototype.onExecuted;
                nodeType.prototype.onExecuted = function (message) {
                    onExecutedDisplayAny?.apply(this, arguments);
                    updateWidget(this, "displaytext", message["text"].join(""));
                };
                break;

            case "ImageScalerForSDModels-":
            case "GetImageSize-":
            case "ImageScaleBySpecifiedSide-":
            case "ComputeImageScaleRatio-":
                const onExecutedImage = nodeType.prototype.onExecuted;
                nodeType.prototype.onExecuted = function (message) {
                    onExecutedImage?.apply(this, arguments);
                    let value = message["width"].join("") + "x" + message["height"].join("");
                    if (nodeData.name === "GetImageSize-") {
                        value += "x" + message["count"].join("");
                    }
                    if (nodeData.name === "ComputeImageScaleRatio-") {
                        value += "x" + message["rescale_ratio"].join("");
                    }
                    updateWidget(this, "return_text", value);
                };
                break;
        }

        // 辅助函数用于更新或创建widget
        function updateWidget(node, widgetName, value) {
            let textWidget = node.widgets && node.widgets.find(w => w.name === widgetName);
            if (!textWidget) {
                textWidget = ComfyWidgets["STRING"](node, widgetName, ["STRING", { multiline: true }], app).widget;
                textWidget.inputEl.readOnly = true;
                textWidget.inputEl.style.border = "none";
                textWidget.inputEl.style.backgroundColor = "transparent";
            }
            textWidget.value = value;
        }
                
    },
});