From b4e7ee05e6d7d8a59549ab7587c67c06ef269a27 Mon Sep 17 00:00:00 2001
From: Cohee <18619528+Cohee1207@users.noreply.github.com>
Date: Wed, 24 Jan 2024 16:10:50 +0200
Subject: [PATCH] Remove regex replace strategy selector
---
public/scripts/extensions/regex/editor.html | 11 +--
public/scripts/extensions/regex/engine.js | 91 ---------------------
public/scripts/extensions/regex/index.js | 9 --
3 files changed, 2 insertions(+), 109 deletions(-)
diff --git a/public/scripts/extensions/regex/editor.html b/public/scripts/extensions/regex/editor.html
index 3c3f65aae..96d3238cf 100644
--- a/public/scripts/extensions/regex/editor.html
+++ b/public/scripts/extensions/regex/editor.html
@@ -76,7 +76,7 @@
-
+
Affects
-
+
Other Options
-
- Replacement Strategy
-
-
diff --git a/public/scripts/extensions/regex/engine.js b/public/scripts/extensions/regex/engine.js
index 358fc15ae..38a10cb0f 100644
--- a/public/scripts/extensions/regex/engine.js
+++ b/public/scripts/extensions/regex/engine.js
@@ -19,14 +19,6 @@ const regex_placement = {
SLASH_COMMAND: 3,
};
-/**
- * @enum {number} How the regex script should replace the matched string
- */
-const regex_replace_strategy = {
- REPLACE: 0,
- OVERLAY: 1,
-};
-
/**
* Instantiates a regular expression from a string.
* @param {string} input The input string.
@@ -153,86 +145,3 @@ function filterString(rawString, trimStrings, { characterOverride } = {}) {
return finalString;
}
-
-/**
- * Substitutes regex-specific and normal parameters
- * @param {string} rawString
- * @param {string} regexMatch
- * @param {RegexSubstituteParams} params The parameters to use for the regex substitution
- * @returns {string} The substituted string
- * @typedef {{characterOverride?: string, replaceStrategy?: number}} RegexSubstituteParams The parameters to use for the regex substitution
- */
-function substituteRegexParams(rawString, regexMatch, { characterOverride, replaceStrategy } = {}) {
- let finalString = rawString;
- finalString = substituteParams(finalString, undefined, characterOverride);
-
- let overlaidMatch = regexMatch;
- // TODO: Maybe move the for loops into a separate function?
- if (replaceStrategy === regex_replace_strategy.OVERLAY) {
- const splitReplace = finalString.split('{{match}}');
-
- // There's a prefix
- if (splitReplace[0]) {
- // Fetch the prefix
- const splicedPrefix = spliceSymbols(splitReplace[0], false);
-
- // Sequentially remove all occurrences of prefix from start of split
- const splitMatch = overlaidMatch.split(splicedPrefix);
- let sliceNum = 0;
- for (let index = 0; index < splitMatch.length; index++) {
- if (splitMatch[index].length === 0) {
- sliceNum++;
- } else {
- break;
- }
- }
-
- overlaidMatch = splitMatch.slice(sliceNum, splitMatch.length).join(splicedPrefix);
- }
-
- // There's a suffix
- if (splitReplace[1]) {
- // Fetch the suffix
- const splicedSuffix = spliceSymbols(splitReplace[1], true);
-
- // Sequential removal of all suffix occurrences from end of split
- const splitMatch = overlaidMatch.split(splicedSuffix);
- let sliceNum = 0;
- for (let index = splitMatch.length - 1; index >= 0; index--) {
- if (splitMatch[index].length === 0) {
- sliceNum++;
- } else {
- break;
- }
- }
-
- overlaidMatch = splitMatch.slice(0, splitMatch.length - sliceNum).join(splicedSuffix);
- }
- }
-
- // Only one match is replaced. This is by design
- finalString = finalString.replace('{{match}}', overlaidMatch) || finalString.replace('{{match}}', regexMatch);
-
- return finalString;
-}
-
-/**
- * Splices common sentence symbols and whitespace from the beginning and end of a string.
- * Using a for loop due to sequential ordering.
- * @param {string} rawString The raw string to splice
- * @param {boolean} isSuffix String is a suffix
- * @returns {string} The spliced string
- */
-function spliceSymbols(rawString, isSuffix) {
- let offset = 0;
-
- for (const ch of isSuffix ? rawString.split('').reverse() : rawString) {
- if (ch.match(/[^\w.,?'!]/)) {
- offset++;
- } else {
- break;
- }
- }
-
- return isSuffix ? rawString.substring(0, rawString.length - offset) : rawString.substring(offset);
-}
diff --git a/public/scripts/extensions/regex/index.js b/public/scripts/extensions/regex/index.js
index c5fabdac8..97617bcfe 100644
--- a/public/scripts/extensions/regex/index.js
+++ b/public/scripts/extensions/regex/index.js
@@ -141,9 +141,6 @@ async function onRegexEditorOpenClick(existingId) {
editorHtml
.find('input[name="substitute_regex"]')
.prop('checked', existingScript.substituteRegex ?? false);
- editorHtml
- .find('select[name="replace_strategy_select"]')
- .val(existingScript.replaceStrategy ?? 0);
existingScript.placement.forEach((element) => {
editorHtml
@@ -181,7 +178,6 @@ async function onRegexEditorOpenClick(existingId) {
replaceString: editorHtml.find('.regex_replace_string').val(),
trimStrings: String(editorHtml.find('.regex_trim_strings').val()).split('\n').filter((e) => e.length !== 0) || [],
substituteRegex: editorHtml.find('input[name="substitute_regex"]').prop('checked'),
- replaceStrategy: Number(editorHtml.find('select[name="replace_strategy_select"]').find(':selected').val()) ?? 0,
};
const rawTestString = String(editorHtml.find('#regex_test_input').val());
const result = runRegexScript(testScript, rawTestString);
@@ -224,11 +220,6 @@ async function onRegexEditorOpenClick(existingId) {
editorHtml
.find('input[name="substitute_regex"]')
.prop('checked'),
- replaceStrategy:
- parseInt(editorHtml
- .find('select[name="replace_strategy_select"]')
- .find(':selected')
- .val()) ?? 0,
};
saveRegexScript(newRegexScript, existingScriptIndex);