From e40d43e4d9cd44f52c30086af3a8351f464904b9 Mon Sep 17 00:00:00 2001 From: RD WebDesign Date: Fri, 17 Mar 2023 15:22:55 -0300 Subject: [PATCH] Fix NaN error message when FTL is offline Signed-off-by: RD WebDesign --- scripts/pi-hole/js/index.js | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/scripts/pi-hole/js/index.js b/scripts/pi-hole/js/index.js index a1b84e605..f27b17496 100644 --- a/scripts/pi-hole/js/index.js +++ b/scripts/pi-hole/js/index.js @@ -678,7 +678,6 @@ function updateSummaryData(runOnce) { updateTopLists(); } - var formatter = new Intl.NumberFormat(); //Element name might have a different name to the property of the API so we split it at | [ "ads_blocked_today|queries_blocked_today", @@ -691,9 +690,17 @@ function updateSummaryData(runOnce) { var apiName = apiElName[0]; var elName = apiElName[1]; var $todayElement = elName ? $("span#" + elName) : $("span#" + apiName); - // Round to one decimal place and format locale-aware - var text = formatter.format(Math.round(data[apiName] * 10) / 10); - var textData = idx === 2 && data[apiName] !== "to" ? text + "%" : text; + + var textData = data[apiName]; + if (!FTLoffline) { + // Only format as number if FTL is online + var formatter = new Intl.NumberFormat(); + + // Round to one decimal place and format locale-aware + var text = formatter.format(Math.round(data[apiName] * 10) / 10); + textData = idx === 2 && data[apiName] !== "to" ? text + "%" : text; + } + if ($todayElement.text() !== textData && $todayElement.text() !== textData + "%") { $todayElement.addClass("glow"); $todayElement.text(textData);