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