File size: 1,174 Bytes
1b80e0f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import { app } from "/scripts/app.js";
import { ComfyWidgets } from "/scripts/widgets.js";

app.registerExtension({
	name: "n.DynamicPrompt",
	async beforeRegisterNodeDef(nodeType, nodeData, app) {
		
		if (nodeData.name === "DynamicPrompt") {
			console.warn("DynamicPrompt detected")
			
			const onExecuted = nodeType.prototype.onExecuted;

	
			nodeType.prototype.onExecuted = function (message) {
				onExecuted?.apply(this, arguments);
				
				const pos_cached = this.widgets.findIndex((w) => w.name === "cached");
				console.warn("value:"+pos_cached)
				
				if (this.widgets) {
					const pos_text = this.widgets.findIndex((w) => w.name === "text");
					if (pos_text !== -1) {
						for (let i = pos_text; i < this.widgets.length; i++) {
							this.widgets[i].onRemove?.();
						}
						this.widgets.length = pos_text;
					}
				}


				if (this.widgets[pos_cached].value === "NO") {
					
					const w = ComfyWidgets["STRING"](this, "text", ["STRING", { multiline: true }], app);
					//random seed
					var rnm = Math.floor(Math.random() * 10000)
					w.widget.value = rnm;
					
				
				}
			
			};
		}
	},
});