Prevent changing localstorage unless it is available

This commit is contained in:
Jeremy "EndenDragon" Zhang 2021-07-04 14:31:29 -07:00 committed by GitHub
parent 6c80855829
commit a75f0a276b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -564,7 +564,9 @@ var passedCookieTest = true; // If passed cross origin test
$("[name=richembed_toggle_radiobtn]").click(function (event) { $("[name=richembed_toggle_radiobtn]").click(function (event) {
display_richembeds = event.target.value == "true"; display_richembeds = event.target.value == "true";
if (localstorage_avaliable) {
localStorage.setItem("display_richembeds", display_richembeds); localStorage.setItem("display_richembeds", display_richembeds);
}
$("[name=richembed_toggle_radiobtn][value=" + display_richembeds + "]").prop("checked", true); $("[name=richembed_toggle_radiobtn][value=" + display_richembeds + "]").prop("checked", true);
}); });
var localstore_display_richembeds = ""; var localstore_display_richembeds = "";
@ -662,9 +664,11 @@ var passedCookieTest = true; // If passed cross origin test
if ($.inArray(sound, soundTypes) != -1) { if ($.inArray(sound, soundTypes) != -1) {
notification_sound_setting = sound; notification_sound_setting = sound;
$("[name=notification_sound_radiobtn][value=" + sound + "]").prop("checked", true); $("[name=notification_sound_radiobtn][value=" + sound + "]").prop("checked", true);
if (localstorage_avaliable) {
localStorage.setItem("notification_sound", sound); localStorage.setItem("notification_sound", sound);
} }
} }
}
function changeTheme(theme, keep_custom_css, modifyLocalStore) { function changeTheme(theme, keep_custom_css, modifyLocalStore) {
if (theme === undefined) { if (theme === undefined) {
@ -679,7 +683,7 @@ var passedCookieTest = true; // If passed cross origin test
if (theme == "") { if (theme == "") {
$("#css-theme").attr("href", ""); $("#css-theme").attr("href", "");
$("#user-defined-css").text(user_def_css); $("#user-defined-css").text(user_def_css);
if (modifyLocalStore) { if (modifyLocalStore && localstorage_avaliable) {
localStorage.removeItem("theme"); localStorage.removeItem("theme");
} }
} else if ($.inArray(theme, theme_options) != -1 || theme == null) { } else if ($.inArray(theme, theme_options) != -1 || theme == null) {
@ -690,7 +694,7 @@ var passedCookieTest = true; // If passed cross origin test
} }
if (theme) { if (theme) {
$("#css-theme").attr("href", "/static/themes/" + theme + "/css/style.css"); $("#css-theme").attr("href", "/static/themes/" + theme + "/css/style.css");
if (modifyLocalStore) { if (modifyLocalStore && localstorage_avaliable) {
localStorage.setItem("theme", theme); localStorage.setItem("theme", theme);
} }
} }
@ -824,7 +828,9 @@ var passedCookieTest = true; // If passed cross origin test
$(".dblballoon").find("i").click(function (event) { $(".dblballoon").find("i").click(function (event) {
event.preventDefault(); event.preventDefault();
$(".brand-logo").hideBalloon(); $(".brand-logo").hideBalloon();
if (localstorage_avaliable) {
localStorage.setItem("hideDiscordBotsOrgVoteAdUntil", now.add(3, "days").toISOString()); localStorage.setItem("hideDiscordBotsOrgVoteAdUntil", now.add(3, "days").toISOString());
}
}).css("cursor", "pointer"); }).css("cursor", "pointer");
} }
}); });