diff --git a/public/scripts/extensions/regex/editor.html b/public/scripts/extensions/regex/editor.html index e19d11777..31bb8eada 100644 --- a/public/scripts/extensions/regex/editor.html +++ b/public/scripts/extensions/regex/editor.html @@ -89,6 +89,10 @@ Run On Edit + diff --git a/public/scripts/extensions/regex/engine.js b/public/scripts/extensions/regex/engine.js index d4dc484e1..073eb7028 100644 --- a/public/scripts/extensions/regex/engine.js +++ b/public/scripts/extensions/regex/engine.js @@ -45,13 +45,14 @@ function getRegexedString(rawString, placement) { // Runs the provided regex script on the given string function runRegexScript(regexScript, rawString) { - if (!!(regexScript.disabled)) { + if (!regexScript || !!(regexScript.disabled) || !regexScript?.findRegex || !rawString) { return; } let match; let newString; - const findRegex = regexFromString(regexScript.findRegex); + console.log(regexScript.substituteRegex ? substituteParams(regexScript.findRegex) : regexScript.findRegex) + const findRegex = regexFromString(regexScript.substituteRegex ? substituteParams(regexScript.findRegex) : regexScript.findRegex); while ((match = findRegex.exec(rawString)) !== null) { const fencedMatch = match[0]; const capturedMatch = match[1]; diff --git a/public/scripts/extensions/regex/index.js b/public/scripts/extensions/regex/index.js index d839b7769..e577437ba 100644 --- a/public/scripts/extensions/regex/index.js +++ b/public/scripts/extensions/regex/index.js @@ -97,16 +97,25 @@ async function onRegexEditorOpenClick(existingId) { existingScriptIndex = extension_settings.regex.findIndex((script) => script.scriptName === existingScriptName); if (existingScriptIndex !== -1) { const existingScript = extension_settings.regex[existingScriptIndex]; - editorHtml.find(`.regex_script_name`).val(existingScript.scriptName); - editorHtml.find(`.find_regex`).val(existingScript.findRegex); - editorHtml.find(`.regex_replace_string`).val(existingScript.replaceString); + if (existingScript.scriptName) { + editorHtml.find(`.regex_script_name`).val(existingScript.scriptName); + } else { + toastr.error("This script doesn't have a name! Please delete it.") + return; + } + + editorHtml.find(`.find_regex`).val(existingScript.findRegex || ""); + editorHtml.find(`.regex_replace_string`).val(existingScript.replaceString || ""); editorHtml.find(`.regex_trim_strings`).val(existingScript.trimStrings?.join("\n") || []); editorHtml .find(`input[name="disabled"]`) .prop("checked", existingScript.disabled ?? false); editorHtml .find(`input[name="run_on_edit"]`) - .prop("checked", existingScript.runOnEdit); + .prop("checked", existingScript.runOnEdit ?? false); + editorHtml + .find(`input[name="substitute_regex"]`) + .prop("checked", existingScript.substituteRegex ?? false); existingScript.placement.forEach((element) => { editorHtml @@ -145,6 +154,10 @@ async function onRegexEditorOpenClick(existingId) { runOnEdit: editorHtml .find(`input[name="run_on_edit"]`) + .prop("checked"), + substituteRegex: + editorHtml + .find(`input[name="substitute_regex"]`) .prop("checked") };