try catch errors for local storage
This commit is contained in:
parent
cca1269f4a
commit
12ca7da27a
2 changed files with 52 additions and 9 deletions
File diff suppressed because one or more lines are too long
|
|
@ -1276,8 +1276,20 @@ function InitialHTMLPopulate(divIdObj) {
|
||||||
AppendHTML(divIdObj.achievements, FLEUR_DIVIDE);
|
AppendHTML(divIdObj.achievements, FLEUR_DIVIDE);
|
||||||
|
|
||||||
// Check local storage first to set proper checkbox state before the below functions start (default is always unchecked)
|
// Check local storage first to set proper checkbox state before the below functions start (default is always unchecked)
|
||||||
|
try {
|
||||||
if (localStorage.getItem("hkCheckboxHints") === "checked") document.getElementById("checkbox-hints").checked = true;
|
if (localStorage.getItem("hkCheckboxHints") === "checked") document.getElementById("checkbox-hints").checked = true;
|
||||||
|
}
|
||||||
|
catch (error) {
|
||||||
|
console.log(error);
|
||||||
|
}
|
||||||
|
try {
|
||||||
if (localStorage.getItem("hkCheckboxSpoilers") === "checked") document.getElementById("checkbox-spoilers").checked = true;
|
if (localStorage.getItem("hkCheckboxSpoilers") === "checked") document.getElementById("checkbox-spoilers").checked = true;
|
||||||
|
}
|
||||||
|
catch (error) {
|
||||||
|
console.log(error);
|
||||||
|
}
|
||||||
|
// if (localStorage.getItem("hkCheckboxHints") === "checked") document.getElementById("checkbox-hints").checked = true;
|
||||||
|
// if (localStorage.getItem("hkCheckboxSpoilers") === "checked") document.getElementById("checkbox-spoilers").checked = true;
|
||||||
|
|
||||||
// Prevents wrong checkbox behaviour (must run after everything is finished)
|
// Prevents wrong checkbox behaviour (must run after everything is finished)
|
||||||
CheckboxHintsToggle();
|
CheckboxHintsToggle();
|
||||||
|
|
@ -1315,16 +1327,26 @@ function CheckboxHintsToggle(param = "none") {
|
||||||
checkboxId.value = "hints-off";
|
checkboxId.value = "hints-off";
|
||||||
|
|
||||||
// remember this choice for subsequent page visits and browser restarts
|
// remember this choice for subsequent page visits and browser restarts
|
||||||
|
try {
|
||||||
localStorage.setItem("hkCheckboxHints", "unchecked");
|
localStorage.setItem("hkCheckboxHints", "unchecked");
|
||||||
}
|
}
|
||||||
|
catch (error) {
|
||||||
|
console.log(error);
|
||||||
|
}
|
||||||
|
}
|
||||||
// This runs when the checkbox is checked
|
// This runs when the checkbox is checked
|
||||||
else {
|
else {
|
||||||
document.getElementById("hk-hints").classList.remove("hidden");
|
document.getElementById("hk-hints").classList.remove("hidden");
|
||||||
checkboxId.value = "hints-on";
|
checkboxId.value = "hints-on";
|
||||||
|
|
||||||
// remember this choice for subsequent page visits and browser restarts
|
// remember this choice for subsequent page visits and browser restarts
|
||||||
|
try {
|
||||||
localStorage.setItem("hkCheckboxHints", "checked");
|
localStorage.setItem("hkCheckboxHints", "checked");
|
||||||
}
|
}
|
||||||
|
catch (error) {
|
||||||
|
console.log(error);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1346,7 +1368,12 @@ function CheckboxSpoilersToggle(param = "none") {
|
||||||
checkboxId.checked = false;
|
checkboxId.checked = false;
|
||||||
|
|
||||||
// remember this choice for subsequent page visits and browser restarts
|
// remember this choice for subsequent page visits and browser restarts
|
||||||
|
try {
|
||||||
localStorage.setItem("hkCheckboxSpoilers", "unchecked");
|
localStorage.setItem("hkCheckboxSpoilers", "unchecked");
|
||||||
|
}
|
||||||
|
catch (error) {
|
||||||
|
console.log(error);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case "show":
|
case "show":
|
||||||
for (let i = 0; i < length; i++) {
|
for (let i = 0; i < length; i++) {
|
||||||
|
|
@ -1356,7 +1383,12 @@ function CheckboxSpoilersToggle(param = "none") {
|
||||||
checkboxId.checked = true;
|
checkboxId.checked = true;
|
||||||
|
|
||||||
// remember this choice for subsequent page visits and browser restarts
|
// remember this choice for subsequent page visits and browser restarts
|
||||||
|
try {
|
||||||
localStorage.setItem("hkCheckboxSpoilers", "checked");
|
localStorage.setItem("hkCheckboxSpoilers", "checked");
|
||||||
|
}
|
||||||
|
catch (error) {
|
||||||
|
console.log(error);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
// This runs when the checkbox is not checked
|
// This runs when the checkbox is not checked
|
||||||
|
|
@ -1367,8 +1399,14 @@ function CheckboxSpoilersToggle(param = "none") {
|
||||||
checkboxId.value = "spoilers-off";
|
checkboxId.value = "spoilers-off";
|
||||||
|
|
||||||
// remember this choice for subsequent page visits and browser restarts
|
// remember this choice for subsequent page visits and browser restarts
|
||||||
|
try {
|
||||||
localStorage.setItem("hkCheckboxSpoilers", "unchecked");
|
localStorage.setItem("hkCheckboxSpoilers", "unchecked");
|
||||||
}
|
}
|
||||||
|
catch (error) {
|
||||||
|
console.log(error);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
// This runs when the checkbox is checked
|
// This runs when the checkbox is checked
|
||||||
else {
|
else {
|
||||||
for (let i = 0; i < length; i++) {
|
for (let i = 0; i < length; i++) {
|
||||||
|
|
@ -1377,8 +1415,13 @@ function CheckboxSpoilersToggle(param = "none") {
|
||||||
checkboxId.value = "spoilers-on";
|
checkboxId.value = "spoilers-on";
|
||||||
|
|
||||||
// remember this choice for subsequent page visits and browser restarts
|
// remember this choice for subsequent page visits and browser restarts
|
||||||
|
try {
|
||||||
localStorage.setItem("hkCheckboxSpoilers", "checked");
|
localStorage.setItem("hkCheckboxSpoilers", "checked");
|
||||||
}
|
}
|
||||||
|
catch (error) {
|
||||||
|
console.log(error);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue