diff --git a/scripts/pi-hole/js/db_lists.js b/scripts/pi-hole/js/db_lists.js index 4e21ad6d..aec1e08c 100644 --- a/scripts/pi-hole/js/db_lists.js +++ b/scripts/pi-hole/js/db_lists.js @@ -85,17 +85,11 @@ function updateTopClientsChart() { percentage = (data.top_sources[client] / sum) * 100; clienttable.append( - " " + - clientname + - " " + - data.top_sources[client] + - '
' + " " + + utils.addTD(clientname) + + utils.addTD(data.top_sources[client]) + + utils.addTD(utils.colorBar(percentage, sum, "progress-bar-blue")) + + " " ); } } @@ -132,17 +126,11 @@ function updateTopDomainsChart() { percentage = (data.top_domains[domain] / sum) * 100; domaintable.append( - " " + - domain + - " " + - data.top_domains[domain] + - '
' + " " + + utils.addTD(domain) + + utils.addTD(data.top_domains[domain]) + + utils.addTD(utils.colorBar(percentage, sum, "queries-permitted")) + + " " ); } } @@ -179,17 +167,11 @@ function updateTopAdsChart() { percentage = (data.top_ads[ad] / sum) * 100; adtable.append( - " " + - ad + - " " + - data.top_ads[ad] + - '
' + " " + + utils.addTD(ad) + + utils.addTD(data.top_ads[ad]) + + utils.addTD(utils.colorBar(percentage, sum, "queries-blocked")) + + " " ); } } diff --git a/scripts/pi-hole/js/index.js b/scripts/pi-hole/js/index.js index 9dc8612e..ba962611 100644 --- a/scripts/pi-hole/js/index.js +++ b/scripts/pi-hole/js/index.js @@ -548,17 +548,11 @@ function updateTopClientsChart() { ""; percentage = (data.top_sources[client] / data.dns_queries_today) * 100; clienttable.append( - " " + - url + - " " + - data.top_sources[client] + - '
' + " " + + utils.addTD(url) + + utils.addTD(data.top_sources[client]) + + utils.addTD(utils.colorBar(percentage, data.dns_queries_today, "progress-bar-blue")) + + " " ); } } @@ -594,17 +588,11 @@ function updateTopClientsChart() { ""; percentage = (data.top_sources_blocked[client] / data.ads_blocked_today) * 100; clientblockedtable.append( - " " + - url + - " " + - data.top_sources_blocked[client] + - '
' + " " + + utils.addTD(url) + + utils.addTD(data.top_sources_blocked[client]) + + utils.addTD(utils.colorBar(percentage, data.ads_blocked_today, "progress-bar-blue")) + + " " ); } } @@ -651,17 +639,11 @@ function updateTopLists() { url = '' + urlText + ""; percentage = (data.top_queries[domain] / data.dns_queries_today) * 100; domaintable.append( - " " + - url + - " " + - data.top_queries[domain] + - '
' + " " + + utils.addTD(url) + + utils.addTD(data.top_queries[domain]) + + utils.addTD(utils.colorBar(percentage, data.dns_queries_today, "queries-permitted")) + + " " ); } } @@ -684,17 +666,11 @@ function updateTopLists() { url = '' + urlText + ""; percentage = (data.top_ads[domain] / data.ads_blocked_today) * 100; adtable.append( - " " + - url + - " " + - data.top_ads[domain] + - '
' + " " + + utils.addTD(url) + + utils.addTD(data.top_ads[domain]) + + utils.addTD(utils.colorBar(percentage, data.ads_blocked_today, "queries-blocked")) + + " " ); } } diff --git a/scripts/pi-hole/js/utils.js b/scripts/pi-hole/js/utils.js index dffbb1b2..7229231f 100644 --- a/scripts/pi-hole/js/utils.js +++ b/scripts/pi-hole/js/utils.js @@ -337,6 +337,17 @@ function addFromQueryLog(domain, list) { }); } +// Helper functions to format the progress bars used on the Dashboard and Long-term Lists +function addTD(content) { + return "" + content + " "; +} + +function colorBar(percentage, total, cssClass) { + var title = percentage.toFixed(1) + "% of " + total; + var bar = '
'; + return '
' + bar + "
"; +} + window.utils = (function () { return { escapeHtml: escapeHtml, @@ -357,5 +368,7 @@ window.utils = (function () { validateMAC: validateMAC, validateHostname: validateHostname, addFromQueryLog: addFromQueryLog, + addTD: addTD, + colorBar: colorBar, }; })();