mirror of
https://git.datalinker.icu/kijai/ComfyUI-KJNodes.git
synced 2025-12-09 21:04:41 +08:00
41 lines
1.3 KiB
JavaScript
41 lines
1.3 KiB
JavaScript
import { api } from "../../../scripts/api.js";
|
|
import { app } from "../../../scripts/app.js";
|
|
|
|
app.registerExtension({
|
|
name: "KJNodes.browserstatus",
|
|
setup() {
|
|
api.addEventListener("status", ({ detail }) => {
|
|
let title = "ComfyUI";
|
|
let favicon = "green";
|
|
let queueRemaining = detail && detail.exec_info.queue_remaining;
|
|
|
|
if (queueRemaining) {
|
|
favicon = "red";
|
|
|
|
title = `00% - ${queueRemaining} | ${title}`;
|
|
}
|
|
let link = document.querySelector("link[rel~='icon']");
|
|
if (!link) {
|
|
link = document.createElement("link");
|
|
link.rel = "icon";
|
|
document.head.appendChild(link);
|
|
}
|
|
link.href = new URL(`../${favicon}.png`, import.meta.url);
|
|
document.title = title;
|
|
|
|
});
|
|
//add progress to the title
|
|
api.addEventListener("progress", ({ detail }) => {
|
|
const { value, max } = detail;
|
|
const progress = Math.floor((value / max) * 100);
|
|
let title = document.title;
|
|
|
|
if (!isNaN(progress) && progress >= 0 && progress <= 100) {
|
|
const paddedProgress = String(progress).padStart(2, '0');
|
|
title = `${paddedProgress}% ${title.replace(/^\d+%\s/, '')}`;
|
|
}
|
|
|
|
document.title = title;
|
|
});
|
|
},
|
|
}); |