From 0e45aa7e5892df3ab252e77c8355cab006537722 Mon Sep 17 00:00:00 2001 From: kingbri Date: Mon, 24 Jul 2023 23:21:54 -0400 Subject: [PATCH] Regex: Fix saving logic - Don't save if the name is empty or undefined - Warn if the find regex isn't found - Warn if the "Affects" checkbox isn't selected This allows for edits to be preserved even if a user incorrectly changes something with the regex script itself. Signed-off-by: kingbri --- public/scripts/extensions/regex/index.js | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/public/scripts/extensions/regex/index.js b/public/scripts/extensions/regex/index.js index 610fe5e09..103f294a1 100644 --- a/public/scripts/extensions/regex/index.js +++ b/public/scripts/extensions/regex/index.js @@ -5,13 +5,14 @@ import { regex_placement } from "./engine.js"; async function saveRegexScript(regexScript, existingScriptIndex) { // If not editing - if (existingScriptIndex === -1) { - // Is the script name undefined? - if (!regexScript.scriptName) { - toastr.error(`Could not save regex script: The script name was undefined or empty!`); - return; - } + // Is the script name undefined or empty? + if (!regexScript.scriptName) { + toastr.error(`Could not save regex script: The script name was undefined or empty!`); + return; + } + + if (existingScriptIndex === -1) { // Does the script name already exist? if (extension_settings.regex.find((e) => e.scriptName === regexScript.scriptName)) { toastr.error(`Could not save regex script: A script with name ${regexScript.scriptName} already exists.`); @@ -29,14 +30,12 @@ async function saveRegexScript(regexScript, existingScriptIndex) { // Is a find regex present? if (regexScript.findRegex.length === 0) { - toastr.error(`Could not save regex script: A find regex is required!`); - return; + toastr.warning(`This regex script will not work, but was saved anyway: A find regex isn't present.`); } // Is there someplace to place results? if (regexScript.placement.length === 0) { - toastr.error(`Could not save regex script: One placement checkbox must be selected!`); - return; + toastr.warning(`This regex script will not work, but was saved anyway: One "Affects" checkbox must be selected!`); } if (existingScriptIndex !== -1) { @@ -140,7 +139,7 @@ async function onRegexEditorOpenClick(existingId) { .prop("checked", true); editorHtml - .find(`input[name="replace_position"][value="0"]`) + .find(`input[name="replace_position"][value="1"]`) .prop("checked", true); }