diff --git a/scripts/pi-hole/js/db_queries.js b/scripts/pi-hole/js/db_queries.js index 306b43a02..3763791e7 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 763e8ae92..5e3866229 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 7507e46da..091a6f98f 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 964898c31..5f5c6430d 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 7229231fa..b9e1a5733 100644 --- a/scripts/pi-hole/js/utils.js +++ b/scripts/pi-hole/js/utils.js @@ -229,13 +229,25 @@ 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) { + var data; // Receive previous state from client's local storage area - var data = localStorage.getItem(itemName); + if (localStorage === null) { + var item = backupStorage[itemName]; + data = typeof item === "undefined" ? null : item; + } else { + data = localStorage.getItem(itemName); + } + // Return if not available if (data === null) { return null; @@ -259,7 +271,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) {