File size: 959 Bytes
1e3b872
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import { app } from "../../../scripts/app.js";

app.registerExtension({
	name: "pysssss.PlaySound",
	async beforeRegisterNodeDef(nodeType, nodeData, app) {
		if (nodeData.name === "PlaySound|pysssss") {
			const onExecuted = nodeType.prototype.onExecuted;
			nodeType.prototype.onExecuted = async function () {
				onExecuted?.apply(this, arguments);
				if (this.widgets[0].value === "on empty queue") {
					if (app.ui.lastQueueSize !== 0) {
						await new Promise((r) => setTimeout(r, 500));
					}
					if (app.ui.lastQueueSize !== 0) {
						return;
					}
				}
				let file = this.widgets[2].value;
				if (!file) {
					file = "notify.mp3";
				}
				if (!file.startsWith("http")) {
					if (!file.includes("/")) {
						file = "assets/" + file;
					}
					file = new URL(file, import.meta.url)
				}
				
				const url = new URL(file);
				const audio = new Audio(url);
				audio.volume = this.widgets[1].value;
				audio.play();
			};
		}
	},
});