Merge pull request #2026 from chrismiceli/issue/1119

1119 Privacy - Query Page and Dom.storage
This commit is contained in:
yubiuser
2022-02-10 22:39:39 +01:00
committed by GitHub
5 changed files with 34 additions and 13 deletions

View File

@@ -296,7 +296,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");
}

View File

@@ -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";
}

View File

@@ -231,7 +231,7 @@ $(function () {
fieldtext += '<input type="hidden" name="id" value="' + parseInt(data[4], 10) + '">';
$(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");
}

View File

@@ -358,7 +358,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
@@ -366,7 +366,9 @@ $(function () {
} else {
// Initialize checkbox
bargraphs.prop("checked", true);
localStorage.setItem("barchart_chkbox", true);
if (localStorage) {
localStorage.setItem("barchart_chkbox", true);
}
}
bargraphs.click(function () {
@@ -376,7 +378,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
@@ -384,7 +386,9 @@ $(function () {
} else {
// Initialize checkbox
colorfulQueryLog.prop("checked", false);
localStorage.setItem("colorfulQueryLog_chkbox", false);
if (localStorage) {
localStorage.setItem("colorfulQueryLog_chkbox", false);
}
}
colorfulQueryLog.click(function () {

View File

@@ -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) {