如果我没理解错的话,是想要做到 icon 变颜色?
可供参考:
此模块为 DNS 延迟信息 + Flush DNS 功能,按照延迟高低分配了不同颜色的🐰和🐢图标,使用的是简单的 let 命令。
!(async () => {
let delay = ((await httpAPI("/v1/test/dns_delay")).delay * 1000).toFixed(2);
let animal;
let iconColour;
if (delay >= 50) {
animal = "tortoise.fill",
iconColour = "#3647A1"
} else {
animal = "hare.fill",
iconColour = "#F2CC8F"
}
let panel = {
title: `⌛️ DNS Check\t\t🔄 Flush`,
content: ` Result: ${delay} ms`,
icon: animal,
"icon-color": iconColour
},
showServer = true,
dnsCache;
if (showServer) {
dnsCache = (await httpAPI("/v1/dns", "GET")).dnsCache;
dnsCache = [...new Set(dnsCache.map((d) => d.server))].toString().replace(/,/g, "\n");
}
if ($trigger == "button") await httpAPI("/v1/dns/flush");
$done(panel);
})();
function httpAPI(path = "", method = "POST", body = null) {
return new Promise((resolve) => {
$httpAPI(method, path, body, (result) => {
resolve(result);
});
});
}