From 3bd702563cb0d8de736f983b55df62423a723f46 Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Sat, 2 Jan 2021 20:10:12 -0800 Subject: [PATCH 1/3] Date.now() fixes Signed-off-by: Dan Schaper --- scripts/pi-hole/js/footer.js | 6 +++--- scripts/pi-hole/js/network.js | 5 ----- 2 files changed, 3 insertions(+), 8 deletions(-) diff --git a/scripts/pi-hole/js/footer.js b/scripts/pi-hole/js/footer.js index 32dbc84e..8b8af3e9 100644 --- a/scripts/pi-hole/js/footer.js +++ b/scripts/pi-hole/js/footer.js @@ -44,7 +44,7 @@ function countDown() { var ena = $("#enableLabel"); var enaT = $("#enableTimer"); var target = new Date(parseInt(enaT.html(), 10)); - var seconds = Math.round((target.getTime() - new Date().getTime()) / 1000); + var seconds = Math.round((target.getTime() - Date.now() / 1000); if (seconds > 0) { setTimeout(countDown, 1000); @@ -81,7 +81,7 @@ function piholeChange(action, duration) { btnStatus.html(""); piholeChanged("disabled"); if (duration > 0) { - enaT.html(new Date().getTime() + duration * 1000); + enaT.html(Date.now() + duration * 1000); setTimeout(countDown, 100); } } @@ -206,7 +206,7 @@ function initCPUtemp() { $(function () { var enaT = $("#enableTimer"); var target = new Date(parseInt(enaT.html(), 10)); - var seconds = Math.round((target.getTime() - new Date().getTime()) / 1000); + var seconds = Math.round((target.getTime() - Date.now()) / 1000); if (seconds > 0) { setTimeout(countDown, 100); } diff --git a/scripts/pi-hole/js/network.js b/scripts/pi-hole/js/network.js index dccc8d0b..40f14167 100644 --- a/scripts/pi-hole/js/network.js +++ b/scripts/pi-hole/js/network.js @@ -31,11 +31,6 @@ function handleAjaxError(xhr, textStatus) { } function getTimestamp() { - if (!Date.now) { - Date.now = function () { - return new Date().getTime(); - }; - } return Math.floor(Date.now() / 1000); } From e763993574e882217420ca58df7b4e5ee31034ee Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Sat, 2 Jan 2021 20:15:30 -0800 Subject: [PATCH 2/3] unicorn/prefer-dom-node-append Signed-off-by: Dan Schaper --- scripts/pi-hole/js/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/pi-hole/js/index.js b/scripts/pi-hole/js/index.js index fa154718..f56d6360 100644 --- a/scripts/pi-hole/js/index.js +++ b/scripts/pi-hole/js/index.js @@ -49,7 +49,7 @@ var customTooltips = function (tooltip) { tooltipEl.style.fontStyle = tooltip._bodyFontStyle; // append Tooltip next to canvas-containing box tooltipEl.ancestor = this._chart.canvas.closest(".box[id]").parentNode; - tooltipEl.ancestor.appendChild(tooltipEl); + tooltipEl.ancestor.append(tooltipEl); } // Hide if no tooltip From 2976254bbc10f3f8c495ceccc5f08f07728d21ce Mon Sep 17 00:00:00 2001 From: Dan Schaper Date: Sat, 2 Jan 2021 20:23:52 -0800 Subject: [PATCH 3/3] unicorn/no-lonely-if Signed-off-by: Dan Schaper --- scripts/pi-hole/js/db_graph.js | 9 +++++---- scripts/pi-hole/js/footer.js | 2 +- scripts/pi-hole/js/network.js | 1 - 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/scripts/pi-hole/js/db_graph.js b/scripts/pi-hole/js/db_graph.js index 402c680c..66ab5f11 100644 --- a/scripts/pi-hole/js/db_graph.js +++ b/scripts/pi-hole/js/db_graph.js @@ -106,10 +106,11 @@ function updateQueriesOverTime() { } for (hour in data.ads_over_time[0]) { - if (Object.prototype.hasOwnProperty.call(data.ads_over_time[0], hour)) { - if (dates.indexOf(parseInt(data.ads_over_time[0][hour], 10)) === -1) { - dates.push(parseInt(data.ads_over_time[0][hour], 10)); - } + if ( + Object.prototype.hasOwnProperty.call(data.ads_over_time[0], hour) && + dates.indexOf(parseInt(data.ads_over_time[0][hour], 10)) === -1 + ) { + dates.push(parseInt(data.ads_over_time[0][hour], 10)); } } diff --git a/scripts/pi-hole/js/footer.js b/scripts/pi-hole/js/footer.js index 8b8af3e9..7612b8ec 100644 --- a/scripts/pi-hole/js/footer.js +++ b/scripts/pi-hole/js/footer.js @@ -44,7 +44,7 @@ function countDown() { var ena = $("#enableLabel"); var enaT = $("#enableTimer"); var target = new Date(parseInt(enaT.html(), 10)); - var seconds = Math.round((target.getTime() - Date.now() / 1000); + var seconds = Math.round((target.getTime() - Date.now()) / 1000); if (seconds > 0) { setTimeout(countDown, 1000); diff --git a/scripts/pi-hole/js/network.js b/scripts/pi-hole/js/network.js index 40f14167..fbe915f0 100644 --- a/scripts/pi-hole/js/network.js +++ b/scripts/pi-hole/js/network.js @@ -31,7 +31,6 @@ function handleAjaxError(xhr, textStatus) { } function getTimestamp() { - return Math.floor(Date.now() / 1000); }