icons & tweaks

This commit is contained in:
2024-01-20 04:49:58 +01:00
parent c36eb8daae
commit de0ae352cb
2 changed files with 24 additions and 23 deletions

View File

@ -1,22 +1,25 @@
const colors = [
'#f00', '#e21c00', '#c83800', '#a50', '#8d7100',
'#718d00', '#6fa100', '#5c8000', '#498000', '#080'
];
function batteryColor(batteryPercent) {
const colors = [
'#f00', '#e21c00', '#c83800', '#a50', '#8d7100',
'#718d00', '#6fa100', '#5c8000', '#498000', '#080'
];
let color;
switch(batteryPercent) {
case -1: color = "green"; break;
case -2: color = "red"; break;
default: color = colors[~~(batteryPercent / 10 + 0.5) - 1]; break;
}
return color;
return colors[({
"-2": 9,
"-1": 0
})[batteryPercent] ?? ~~(batteryPercent / 10 + 0.5) - 1];
}
function batteryLevel(batteryPercent) {
if(batteryPercent == -1)
return "charging";
else if(batteryPercent == -2)
return "not connected";
else
return batteryPercent + "%";
return ({
"-2": "not connected",
"-1": "charging"
})[batteryPercent] ?? batteryPercent + "%";
}
function batteryIcon(batteryPercent) {
return ({
"-2": "action-unavailable",
"-1": "battery-ac-adapter"
})[batteryPercent] ?? "audio-headphones-symbolic";
}