Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1119 Privacy - Query Page and Dom.storage #2026

Merged
merged 4 commits into from
Feb 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion scripts/pi-hole/js/db_queries.js
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}

Expand Down
13 changes: 9 additions & 4 deletions scripts/pi-hole/js/footer.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,9 @@ function countDown() {
} else {
ena.text("Enable");
piholeChanged("enabled");
localStorage.removeItem("countDownTarget");
if (localStorage) {
localStorage.removeItem("countDownTarget");
}
}
}

Expand Down Expand Up @@ -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";
}
Expand All @@ -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)) {
Expand All @@ -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";
}
Expand Down
2 changes: 1 addition & 1 deletion scripts/pi-hole/js/queries.js
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}

Expand Down
12 changes: 8 additions & 4 deletions scripts/pi-hole/js/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -334,15 +334,17 @@ $(".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
bargraphs.prop("checked", chkboxData === "true");
} else {
// Initialize checkbox
bargraphs.prop("checked", true);
localStorage.setItem("barchart_chkbox", true);
if (localStorage) {
localStorage.setItem("barchart_chkbox", true);
}
}

bargraphs.click(function () {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note that I left the click functions for settings a storage object unguarded so there is a console error message to indicate the saving failed. I guarded initialization routines that set storage to prevent further code running during initialization from getting blocked.

Expand All @@ -352,15 +354,17 @@ $(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
colorfulQueryLog.prop("checked", chkboxData === "true");
} else {
// Initialize checkbox
colorfulQueryLog.prop("checked", false);
localStorage.setItem("colorfulQueryLog_chkbox", false);
if (localStorage) {
localStorage.setItem("colorfulQueryLog_chkbox", false);
}
}

colorfulQueryLog.click(function () {
Expand Down
18 changes: 15 additions & 3 deletions scripts/pi-hole/js/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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) {
Expand Down