From 34e45edbda1aa9c76208b010dd6919f356a2cc84 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Sat, 8 Apr 2023 21:16:06 +0200 Subject: [PATCH] Fix warnings MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Christian König --- scripts/pi-hole/js/db_lists.js | 6 +++--- scripts/pi-hole/js/db_queries.js | 12 ++++++------ scripts/pi-hole/js/gravity.js | 6 +++--- scripts/pi-hole/js/groups.js | 2 +- scripts/pi-hole/js/index.js | 16 ++++++++-------- scripts/pi-hole/js/network.js | 6 +++--- scripts/pi-hole/js/queries.js | 6 +++--- scripts/pi-hole/js/settings.js | 24 ++++++++++++------------ scripts/pi-hole/js/utils.js | 20 ++++++++++---------- 9 files changed, 49 insertions(+), 49 deletions(-) diff --git a/scripts/pi-hole/js/db_lists.js b/scripts/pi-hole/js/db_lists.js index aec1e08c..c22ed32b 100644 --- a/scripts/pi-hole/js/db_lists.js +++ b/scripts/pi-hole/js/db_lists.js @@ -76,11 +76,11 @@ function updateTopClientsChart() { data.top_sources[utils.escapeHtml(client)] = data.top_sources[client]; } - if (client.indexOf("|") !== -1) { + if (client.indexOf("|") === -1) { + clientname = client; + } else { var idx = client.indexOf("|"); clientname = client.substr(0, idx); - } else { - clientname = client; } percentage = (data.top_sources[client] / sum) * 100; diff --git a/scripts/pi-hole/js/db_queries.js b/scripts/pi-hole/js/db_queries.js index 535d38ac..133b3f4e 100644 --- a/scripts/pi-hole/js/db_queries.js +++ b/scripts/pi-hole/js/db_queries.js @@ -95,15 +95,15 @@ var tableApi, statistics; function handleAjaxError(xhr, textStatus) { if (textStatus === "timeout") { alert("The server took too long to send the data."); - } else if (xhr.responseText.indexOf("Connection refused") !== -1) { - alert("An error occurred while loading the data: Connection refused. Is FTL running?"); - } else { + } else if (xhr.responseText.indexOf("Connection refused") === -1) { alert( "An unknown error occurred while loading the data.\n" + xhr.responseText + "\nCheck the server's log files (/var/log/lighttpd/error-pihole.log) for details.\n\nYou may need to increase PHP memory limit." + "\n\nYou can find more info in pi-hole's FAQ:\nhttps://docs.pi-hole.net/main/faq/#error-while-loading-data-from-the-long-term-database" ); + } else { + alert("An error occurred while loading the data: Connection refused. Is FTL running?"); } $("#all-queries_processing").hide(); @@ -457,10 +457,10 @@ $(function () { }); $("#all-queries tbody").on("click", "button", function () { var data = tableApi.row($(this).parents("tr")).data(); - if ([1, 4, 5, 9, 10, 11].indexOf(data[4]) !== -1) { - utils.addFromQueryLog(data[2], "white"); - } else { + if ([1, 4, 5, 9, 10, 11].indexOf(data[4]) === -1) { utils.addFromQueryLog(data[2], "black"); + } else { + utils.addFromQueryLog(data[2], "white"); } }); diff --git a/scripts/pi-hole/js/gravity.js b/scripts/pi-hole/js/gravity.js index 993dddba..c5fc6465 100644 --- a/scripts/pi-hole/js/gravity.js +++ b/scripts/pi-hole/js/gravity.js @@ -34,11 +34,11 @@ function eventsource() { // Detect ${OVER} var newString = "<------"; - if (e.data.indexOf(newString) !== -1) { + if (e.data.indexOf(newString) === -1) { + ta.append(e.data); + } else { ta.text(ta.text().substring(0, ta.text().lastIndexOf("\n")) + "\n"); ta.append(e.data.replace(newString, "")); - } else { - ta.append(e.data); } }, false diff --git a/scripts/pi-hole/js/groups.js b/scripts/pi-hole/js/groups.js index 30efc063..96dbedb8 100644 --- a/scripts/pi-hole/js/groups.js +++ b/scripts/pi-hole/js/groups.js @@ -79,7 +79,7 @@ $(function () { statusEl.on("change", editGroup); $("td:eq(3)", row).html(''); - var desc = data.description !== null ? data.description : ""; + var desc = data.description === null ? "" : data.description; var descEl = $("#desc_" + data.id, row); descEl.val(utils.unescapeHtml(desc)); descEl.on("change", editGroup); diff --git a/scripts/pi-hole/js/index.js b/scripts/pi-hole/js/index.js index f27b1749..e70d856b 100644 --- a/scripts/pi-hole/js/index.js +++ b/scripts/pi-hole/js/index.js @@ -491,13 +491,13 @@ function updateTopClientsChart() { } client = utils.escapeHtml(client); - if (client.indexOf("|") !== -1) { + if (client.indexOf("|") === -1) { + clientname = client; + clientip = client; + } else { idx = client.indexOf("|"); clientname = client.substr(0, idx); clientip = client.substr(idx + 1, client.length - idx); - } else { - clientname = client; - clientip = client; } url = @@ -531,7 +531,7 @@ function updateTopClientsChart() { } client = utils.escapeHtml(client); - if (client.indexOf("|") !== -1) { + if (client.indexOf("|") === -1) { idx = client.indexOf("|"); clientname = client.substr(0, idx); clientip = client.substr(idx + 1, client.length - idx); @@ -719,10 +719,10 @@ function updateSummaryData(runOnce) { }, 500); }) .done(function () { - if (!FTLoffline) { - setTimer(1); - } else { + if (FTLoffline) { setTimer(10); + } else { + setTimer(1); } }) .fail(function () { diff --git a/scripts/pi-hole/js/network.js b/scripts/pi-hole/js/network.js index 7899374b..80c9591c 100644 --- a/scripts/pi-hole/js/network.js +++ b/scripts/pi-hole/js/network.js @@ -20,10 +20,10 @@ var DAY_IN_SECONDS = 24 * 60 * 60; function handleAjaxError(xhr, textStatus) { if (textStatus === "timeout") { alert("The server took too long to send the data."); - } else if (xhr.responseText.indexOf("Connection refused") !== -1) { - alert("An error occurred while loading the data: Connection refused. Is FTL running?"); - } else { + } else if (xhr.responseText.indexOf("Connection refused") === -1) { alert("An unknown error occurred while loading the data.\n" + xhr.responseText); + } else { + alert("An error occurred while loading the data: Connection refused. Is FTL running?"); } $("#network-entries_processing").hide(); diff --git a/scripts/pi-hole/js/queries.js b/scripts/pi-hole/js/queries.js index 708db6e8..08af373b 100644 --- a/scripts/pi-hole/js/queries.js +++ b/scripts/pi-hole/js/queries.js @@ -31,10 +31,10 @@ var colTypes = ["time", "query type", "domain", "client", "status", "reply type" function handleAjaxError(xhr, textStatus) { if (textStatus === "timeout") { alert("The server took too long to send the data."); - } else if (xhr.responseText.indexOf("Connection refused") !== -1) { - alert("An error occurred while loading the data: Connection refused. Is FTL running?"); - } else { + } else if (xhr.responseText.indexOf("Connection refused") === -1) { alert("An unknown error occurred while loading the data.\n" + xhr.responseText); + } else { + alert("An error occurred while loading the data: Connection refused. Is FTL running?"); } $("#all-queries_processing").hide(); diff --git a/scripts/pi-hole/js/settings.js b/scripts/pi-hole/js/settings.js index 1acf786d..a9820f74 100644 --- a/scripts/pi-hole/js/settings.js +++ b/scripts/pi-hole/js/settings.js @@ -366,15 +366,15 @@ $(function () { var bargraphs = $("#bargraphs"); var chkboxData = localStorage ? localStorage.getItem("barchart_chkbox") : null; - if (chkboxData !== null) { - // Restore checkbox state - bargraphs.prop("checked", chkboxData === "true"); - } else { + if (chkboxData === null) { // Initialize checkbox bargraphs.prop("checked", true); if (localStorage) { localStorage.setItem("barchart_chkbox", true); } + } else { + // Restore checkbox state + bargraphs.prop("checked", chkboxData === "true"); } bargraphs.on("click", function () { @@ -386,15 +386,15 @@ $(function () { var colorfulQueryLog = $("#colorfulQueryLog"); var chkboxData = localStorage ? localStorage.getItem("colorfulQueryLog_chkbox") : null; - if (chkboxData !== null) { - // Restore checkbox state - colorfulQueryLog.prop("checked", chkboxData === "true"); - } else { + if (chkboxData === null) { // Initialize checkbox colorfulQueryLog.prop("checked", false); if (localStorage) { localStorage.setItem("colorfulQueryLog_chkbox", false); } + } else { + // Restore checkbox state + colorfulQueryLog.prop("checked", chkboxData === "true"); } colorfulQueryLog.on("click", function () { @@ -452,15 +452,15 @@ $(function () { var nonfatalwarnigns = $("#hideNonfatalDnsmasqWarnings"); var chkboxData = localStorage ? localStorage.getItem("hideNonfatalDnsmasqWarnings_chkbox") : null; - if (chkboxData !== null) { - // Restore checkbox state - nonfatalwarnigns.prop("checked", chkboxData === "true"); - } else { + if (chkboxData === null) { // Initialize checkbox nonfatalwarnigns.prop("checked", false); if (localStorage) { localStorage.setItem("hideNonfatalDnsmasqWarnings_chkbox", false); } + } else { + // Restore checkbox state + nonfatalwarnigns.prop("checked", chkboxData === "true"); } nonfatalwarnigns.on("click", function () { diff --git a/scripts/pi-hole/js/utils.js b/scripts/pi-hole/js/utils.js index 9d84116a..137db8b6 100644 --- a/scripts/pi-hole/js/utils.js +++ b/scripts/pi-hole/js/utils.js @@ -243,7 +243,7 @@ function stateLoadCallback(itemName) { // Receive previous state from client's local storage area if (localStorage === null) { var item = backupStorage[itemName]; - data = typeof item === "undefined" ? null : item; + data = item === "undefined" ? null : item; } else { data = localStorage.getItem(itemName); } @@ -310,15 +310,7 @@ function addFromQueryLog(domain, list) { }, success: function (response) { alProcessing.hide(); - if (!response.success) { - // Failure - alNetworkErr.hide(); - alCustomErr.html(response.message); - alFailure.fadeIn(1000); - setTimeout(function () { - alertModal.modal("hide"); - }, 10000); - } else { + if (response.success) { // Success alSuccess.children(alDomain).text(domain); alSuccess.children(alList).text(listtype); @@ -326,6 +318,14 @@ function addFromQueryLog(domain, list) { setTimeout(function () { alertModal.modal("hide"); }, 2000); + } else { + // Failure + alNetworkErr.hide(); + alCustomErr.html(response.message); + alFailure.fadeIn(1000); + setTimeout(function () { + alertModal.modal("hide"); + }, 10000); } }, error: function () {