From 99c718296a0a3891f93558a88686d81c2550096e Mon Sep 17 00:00:00 2001 From: Chris Miceli Date: Fri, 24 Dec 2021 22:32:01 -0600 Subject: [PATCH 1/4] 1119 Privacy - Query Page and Dom.storage handle localStorage being null Signed-off-by: Chris Miceli --- scripts/pi-hole/js/db_queries.js | 2 +- scripts/pi-hole/js/footer.js | 13 +++++++++---- scripts/pi-hole/js/queries.js | 2 +- scripts/pi-hole/js/settings.js | 12 ++++++++---- scripts/pi-hole/js/utils.js | 4 ++-- 5 files changed, 21 insertions(+), 12 deletions(-) diff --git a/scripts/pi-hole/js/db_queries.js b/scripts/pi-hole/js/db_queries.js index 306b43a0..3763791e 100644 --- a/scripts/pi-hole/js/db_queries.js +++ b/scripts/pi-hole/js/db_queries.js @@ -294,7 +294,7 @@ $(function () { } $(row).addClass(blocked === true ? "blocked-row" : "allowed-row"); - if (localStorage.getItem("colorfulQueryLog_chkbox") === "true") { + if (localStorage && localStorage.getItem("colorfulQueryLog_chkbox") === "true") { $(row).addClass(blocked === true ? "text-red" : "text-green"); } diff --git a/scripts/pi-hole/js/footer.js b/scripts/pi-hole/js/footer.js index 763e8ae9..5e386622 100644 --- a/scripts/pi-hole/js/footer.js +++ b/scripts/pi-hole/js/footer.js @@ -58,7 +58,9 @@ function countDown() { } else { ena.text("Enable"); piholeChanged("enabled"); - localStorage.removeItem("countDownTarget"); + if (localStorage) { + localStorage.removeItem("countDownTarget"); + } } } @@ -148,7 +150,7 @@ function initCheckboxRadioStyle() { } // Read from local storage, initialize if needed - var chkboxStyle = localStorage.getItem("theme_icheck"); + var chkboxStyle = localStorage ? localStorage.getItem("theme_icheck") : null; if (chkboxStyle === null) { chkboxStyle = "primary"; } @@ -172,7 +174,10 @@ function initCheckboxRadioStyle() { function initCPUtemp() { function setCPUtemp(unit) { - localStorage.setItem("tempunit", tempunit); + if (localStorage) { + localStorage.setItem("tempunit", tempunit); + } + var temperature = parseFloat($("#rawtemp").text()); var displaytemp = $("#tempdisplay"); if (!isNaN(temperature)) { @@ -195,7 +200,7 @@ function initCPUtemp() { } // Read from local storage, initialize if needed - var tempunit = localStorage.getItem("tempunit"); + var tempunit = localStorage ? localStorage.getItem("tempunit") : null; if (tempunit === null) { tempunit = "C"; } diff --git a/scripts/pi-hole/js/queries.js b/scripts/pi-hole/js/queries.js index 7507e46d..091a6f98 100644 --- a/scripts/pi-hole/js/queries.js +++ b/scripts/pi-hole/js/queries.js @@ -231,7 +231,7 @@ $(function () { fieldtext += ''; $(row).addClass(blocked === true ? "blocked-row" : "allowed-row"); - if (localStorage.getItem("colorfulQueryLog_chkbox") === "true") { + if (localStorage && localStorage.getItem("colorfulQueryLog_chkbox") === "true") { $(row).addClass(blocked === true ? "text-red" : "text-green"); } diff --git a/scripts/pi-hole/js/settings.js b/scripts/pi-hole/js/settings.js index 964898c3..5f5c6430 100644 --- a/scripts/pi-hole/js/settings.js +++ b/scripts/pi-hole/js/settings.js @@ -334,7 +334,7 @@ $(".nav-tabs a").on("shown.bs.tab", function (e) { // Bar/Smooth chart toggle $(function () { var bargraphs = $("#bargraphs"); - var chkboxData = localStorage.getItem("barchart_chkbox"); + var chkboxData = localStorage ? localStorage.getItem("barchart_chkbox") : null; if (chkboxData !== null) { // Restore checkbox state @@ -342,7 +342,9 @@ $(function () { } else { // Initialize checkbox bargraphs.prop("checked", true); - localStorage.setItem("barchart_chkbox", true); + if (localStorage) { + localStorage.setItem("barchart_chkbox", true); + } } bargraphs.click(function () { @@ -352,7 +354,7 @@ $(function () { $(function () { var colorfulQueryLog = $("#colorfulQueryLog"); - var chkboxData = localStorage.getItem("colorfulQueryLog_chkbox"); + var chkboxData = localStorage ? localStorage.getItem("colorfulQueryLog_chkbox") : null; if (chkboxData !== null) { // Restore checkbox state @@ -360,7 +362,9 @@ $(function () { } else { // Initialize checkbox colorfulQueryLog.prop("checked", false); - localStorage.setItem("colorfulQueryLog_chkbox", false); + if (localStorage) { + localStorage.setItem("colorfulQueryLog_chkbox", false); + } } colorfulQueryLog.click(function () { diff --git a/scripts/pi-hole/js/utils.js b/scripts/pi-hole/js/utils.js index 7229231f..22ac3887 100644 --- a/scripts/pi-hole/js/utils.js +++ b/scripts/pi-hole/js/utils.js @@ -235,7 +235,7 @@ function stateSaveCallback(itemName, data) { function stateLoadCallback(itemName) { // Receive previous state from client's local storage area - var data = localStorage.getItem(itemName); + var data = localStorage ? localStorage.getItem(itemName) : null; // Return if not available if (data === null) { return null; @@ -259,7 +259,7 @@ function stateLoadCallback(itemName) { function getGraphType() { // Only return line if `barchart_chkbox` is explicitly set to false. Else return bar - return localStorage.getItem("barchart_chkbox") === "false" ? "line" : "bar"; + return localStorage && localStorage.getItem("barchart_chkbox") === "false" ? "line" : "bar"; } function addFromQueryLog(domain, list) { From bb2934e24388932a5d1b28eb4a659c5e9906eda8 Mon Sep 17 00:00:00 2001 From: Chris Miceli Date: Sat, 5 Feb 2022 22:04:14 -0600 Subject: [PATCH 2/4] 1119 Privacy - Query Page and Dom.storage implement memory storage for functionality in case of no storage Signed-off-by: Chris Miceli --- scripts/pi-hole/js/utils.js | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/scripts/pi-hole/js/utils.js b/scripts/pi-hole/js/utils.js index 22ac3887..a6af435d 100644 --- a/scripts/pi-hole/js/utils.js +++ b/scripts/pi-hole/js/utils.js @@ -229,13 +229,20 @@ function setBsSelectDefaults() { }; } +var backupStorage = {}; function stateSaveCallback(itemName, data) { - localStorage.setItem(itemName, JSON.stringify(data)); + if (localStorage === null) { + backupStorage[itemName] = JSON.stringify(data); + } else { + localStorage.setItem(itemName, JSON.stringify(data)); + } } function stateLoadCallback(itemName) { // Receive previous state from client's local storage area - var data = localStorage ? localStorage.getItem(itemName) : null; + var data = + localStorage === null ? backupStorage[itemName] || null : localStorage.getItem(itemName); + // Return if not available if (data === null) { return null; From dde4ac7d3e7a26d29819b7ec0f2f6d26544a2b15 Mon Sep 17 00:00:00 2001 From: Chris Miceli Date: Sat, 5 Feb 2022 22:38:56 -0600 Subject: [PATCH 3/4] 1119 Privacy - Query Page and Dom.storage be explicit for undefined Signed-off-by: Chris Miceli --- scripts/pi-hole/js/utils.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/scripts/pi-hole/js/utils.js b/scripts/pi-hole/js/utils.js index a6af435d..51a9165b 100644 --- a/scripts/pi-hole/js/utils.js +++ b/scripts/pi-hole/js/utils.js @@ -239,9 +239,14 @@ function stateSaveCallback(itemName, data) { } function stateLoadCallback(itemName) { + var data; // Receive previous state from client's local storage area - var data = - localStorage === null ? backupStorage[itemName] || null : localStorage.getItem(itemName); + if (localStorage === null) { + var item = backupStorage[itemName]; + data = typeof item === "undefined" ? null : item; + } else { + localStorage.getItem(itemName); + } // Return if not available if (data === null) { From cb083c061c623b94e412835912f3abffa586af9d Mon Sep 17 00:00:00 2001 From: Chris Miceli Date: Sat, 5 Feb 2022 23:04:29 -0600 Subject: [PATCH 4/4] 1119 Privacy - Query Page and Dom.storage fix else Signed-off-by: Chris Miceli --- scripts/pi-hole/js/utils.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/pi-hole/js/utils.js b/scripts/pi-hole/js/utils.js index 51a9165b..b9e1a573 100644 --- a/scripts/pi-hole/js/utils.js +++ b/scripts/pi-hole/js/utils.js @@ -245,7 +245,7 @@ function stateLoadCallback(itemName) { var item = backupStorage[itemName]; data = typeof item === "undefined" ? null : item; } else { - localStorage.getItem(itemName); + data = localStorage.getItem(itemName); } // Return if not available