diff --git a/files/assets/js/bottom.js b/files/assets/js/bottom.js index 21869aa07..985f3d619 100644 --- a/files/assets/js/bottom.js +++ b/files/assets/js/bottom.js @@ -64,15 +64,51 @@ for (const element of undisable_element) { }); } +async function handleSettingSwitch(event) { + let input = event.currentTarget; + input.disabled = true; + input.classList.add("disabled"); + const form = new FormData(); + form.append("formkey", formkey()); + const res = await fetch( + `/settings/personal?${input.name}=${input.checked}`, + { + method: "POST", + headers: { + xhr: "xhr", + }, + body: form, + }, + ).catch(() => ({ ok: false })); + let message; + if (res.ok) { + ({message} = await res.json()); + // the slur and profanity replacers have special make-permanent switches + if (["slurreplacerswitch", "profanityreplacerswitch"].includes(input.id)) { + document.getElementById( + `${input.id.replace("switch", "")}-perma-link` + ).hidden = !input.checked; + } + } else { + // toggle the input back if the request doesn't go through + input.checked = !input.checked; + } + let oldToast = bootstrap.Toast.getOrCreateInstance( + document.getElementById('toast-post-' + (res.ok ? 'error': 'success')) + ); // intentionally reversed here: this is the old toast + oldToast.hide(); + showToast(res.ok, message); + input.disabled = false; + input.classList.remove("disabled"); +} + const setting_switchs = document.getElementsByClassName('setting_switch'); for (const element of setting_switchs) { if (element.dataset.nonce != nonce) { console.log("Nonce check failed!") continue } - element.addEventListener('change', () => { - postToastSwitch(element,`/settings/personal?${element.name}=${element.checked}`); - }); + element.addEventListener('change', handleSettingSwitch); } const setting_selects = document.getElementsByClassName('setting_select'); diff --git a/files/assets/js/settings_profile.js b/files/assets/js/settings_profile.js index afa34a052..90b6295f7 100644 --- a/files/assets/js/settings_profile.js +++ b/files/assets/js/settings_profile.js @@ -98,14 +98,3 @@ function updatebgselection(){ } } updatebgselection(); - -const sr_toggle = document.getElementById("slurreplacer"); -const sr_link = document.getElementById('slurreplacer-perma-link'); -const pr_toggle = document.getElementById("profanityreplacer"); -const pr_link = document.getElementById('profanityreplacer-perma-link'); -sr_toggle.addEventListener('change', function () { - sr_link.hidden = !sr_toggle.checked; -}); -pr_toggle.addEventListener('change', function () { - pr_link.hidden = !pr_toggle.checked; -}); diff --git a/files/templates/settings/personal.html b/files/templates/settings/personal.html index f67e60c26..8f35fa154 100644 --- a/files/templates/settings/personal.html +++ b/files/templates/settings/personal.html @@ -247,11 +247,13 @@ {{common.text_area_section('profile-signature', '/settings/personal', 'sig', 'Signature', v.sig, 'Limit of 200 characters', 'Enter a signature...', true, false, 200)}} {{common.toggle_section('Private Mode', 'privateswitch', 'private', v.is_private, 'This will hide your profile page from others.', false)}} - {{common.toggle_section('Lifetime donated visiblity', 'lifetimedonated_visible', 'lifetimedonated_visible', v.lifetimedonated_visible, 'Make the "lifetime donated" field in your profile visible to everyone instead of just you.', false)}} + {{common.toggle_section('Lifetime donated visiblity', 'lifetimedonated_visibleswitch', 'lifetimedonated_visible', v.lifetimedonated_visible, 'Make the "lifetime donated" field in your profile visible to everyone instead of just you.', false)}} - {{common.toggle_section('Cursor Marsey', 'cursormarsey', 'cursormarsey', v.cursormarsey, 'Have a cute marsey accompany you during your journey on the site.', false)}} + {{common.toggle_section('Cursor Marsey', 'cursormarseyswitch', 'cursormarsey', v.cursormarsey, 'Have a cute + marsey accompany you during your journey on the site.', false)}} {{common.toggle_section('Spider', 'spiderswitch', 'spider', v.spider, 'Have a spider friend accompany you during your journey on the site.', v.spider > 1)}} - {{common.toggle_section('Marsify', 'marsify', 'marsify', v.marsify, 'Automatically insert relevant marseys into your future comments.', v.marsify > 1)}} + {{common.toggle_section('Marsify', 'marsifyswitch', 'marsify', v.marsify, 'Automatically insert relevant + marseys into your future comments.', v.marsify > 1)}} @@ -268,22 +270,25 @@
Filters
{% set ns = namespace(slurtext='Enable if you would like to automatically replace slurs.', profanitytext='Enable if you would like to automatically replace profanities.') %} - {% if FEATURES['USERS_PERMANENT_WORD_FILTERS'] and v.slurreplacer %} - {% if v.slurreplacer == 1 %} - {% set ns.slurtext = 'Enable if you would like to automatically replace slurs. Make filter permanent for a badge!' %} + {% if FEATURES['USERS_PERMANENT_WORD_FILTERS'] %} + {% if v.slurreplacer == 0 %} + {% set ns.slurtext = 'Enable if you would like to automatically replace slurs. ' %} + {% elif v.slurreplacer == 1 %} + {% set ns.slurtext = 'Enable if you would like to automatically replace slurs. Make filter permanent for a badge!' %} {% else %} {% set ns.slurtext = "You've enabled the slur replacer permanently! ✊🏿" %} {% endif %} - {% endif %} - {% if FEATURES['USERS_PERMANENT_WORD_FILTERS'] and v.profanityreplacer %} - {% if v.profanityreplacer == 1 %} - {% set ns.profanitytext = 'Enable if you would like to automatically replace profanities. Make filter permanent for a badge!' %} + + {% if v.profanityreplacer == 0 %} + {% set ns.profanitytext = 'Enable if you would like to automatically replace profanities. ' %} + {% elif v.profanityreplacer == 1 %} + {% set ns.profanitytext = 'Enable if you would like to automatically replace profanities. Make filter permanent for a badge!' %} {% else %} {% set ns.profanitytext = "You've enabled the profanity replacer permanently! 😇" %} {% endif %} {% endif %} - {{common.toggle_section("Slur Replacer", "slurreplacer", 'slurreplacer', v.slurreplacer, ns.slurtext, FEATURES['USERS_PERMANENT_WORD_FILTERS'] and v.slurreplacer > 1)}} - {{common.toggle_section("Profanity Replacer", "profanityreplacer", 'profanityreplacer', v.profanityreplacer, ns.profanitytext, FEATURES['USERS_PERMANENT_WORD_FILTERS'] and v.profanityreplacer > 1)}} + {{common.toggle_section("Slur Replacer", "slurreplacerswitch", 'slurreplacer', v.slurreplacer, ns.slurtext, FEATURES['USERS_PERMANENT_WORD_FILTERS'] and v.slurreplacer > 1)}} + {{common.toggle_section("Profanity Replacer", "profanityreplacerswitch", 'profanityreplacer', v .profanityreplacer, ns.profanitytext, FEATURES['USERS_PERMANENT_WORD_FILTERS'] and v.profanityreplacer > 1)}}
@@ -352,10 +357,6 @@ {%- endif %} {% endmacro %} -{% if v.slurreplacer == 1 -%} {{permanent_filter_modal('slurreplacer', '/settings/personal', 'slurreplacer', 'Slur Replacer', 'Social Justice Berserker')}} -{%- endif %} -{% if v.profanityreplacer == 1 -%} {{permanent_filter_modal('profanityreplacer', '/settings/personal', 'profanityreplacer', 'Profanity Replacer', 'Soapy-Mouthed Angel')}} -{%- endif %} {% endblock %}