diff --git a/frontend/src/ts/modals/share-test-settings.ts b/frontend/src/ts/modals/share-test-settings.ts index ca6285fe4..aebc3178c 100644 --- a/frontend/src/ts/modals/share-test-settings.ts +++ b/frontend/src/ts/modals/share-test-settings.ts @@ -27,58 +27,37 @@ type SharedTestSettings = [ function updateURL(): void { const baseUrl = location.origin + "?testSettings="; - const settings: SharedTestSettings = [ - null, - null, - null, - null, - null, - null, - null, - null, + const settings: SharedTestSettings = new Array(8).fill( + null + ) as SharedTestSettings; + + const settingsMap = [ + { key: "mode", getValue: () => Config.mode }, + { key: "mode2", getValue: () => getMode2(Config, currentQuote) }, + { key: "customText", getValue: () => CustomText.getData() }, + { key: "punctuation", getValue: () => Config.punctuation }, + { key: "numbers", getValue: () => Config.numbers }, + { key: "language", getValue: () => Config.language }, + { key: "difficulty", getValue: () => Config.difficulty }, + { key: "funbox", getValue: () => Config.funbox }, ]; - if (getCheckboxValue("mode")) { - settings[0] = Config.mode; - } - - if (getCheckboxValue("mode2")) { - settings[1] = getMode2(Config, currentQuote); - } - - if (getCheckboxValue("customText")) { - settings[2] = CustomText.getData(); - } - - if (getCheckboxValue("punctuation")) { - settings[3] = Config.punctuation; - } - - if (getCheckboxValue("numbers")) { - settings[4] = Config.numbers; - } - - if (getCheckboxValue("language")) { - settings[5] = Config.language; - } - - if (getCheckboxValue("difficulty")) { - settings[6] = Config.difficulty; - } - - if (getCheckboxValue("funbox")) { - settings[7] = Config.funbox; + for (const [index, { key, getValue }] of settingsMap.entries()) { + if (getCheckboxValue(key)) { + settings[index] = getValue(); + } } const compressed = compressToURI(JSON.stringify(settings)); - const url = baseUrl + compressed; - $(`#shareTestSettingsModal textarea.url`).val(url); - if (url.length > 2000) { - $(`#shareTestSettingsModal .tooLongWarning`).removeClass("hidden"); - } else { - $(`#shareTestSettingsModal .tooLongWarning`).addClass("hidden"); - } + + updateShareModal(url); +} + +function updateShareModal(url: string): void { + const $modal = $(`#shareTestSettingsModal`); + $modal.find("textarea.url").val(url); + $modal.find(".tooLongWarning").toggleClass("hidden", url.length <= 2000); } function updateSubgroups(): void {