As opposed to making the match variable include the entire regex
match, overlay the replacement string over the regex match and splice
out whatever's already in the replacement string from the regex match.
This new strategy helps save time when editing messages since match
prefix and suffix phrases have a lower chance of being repeated on
every edit. The overlay strategy also preserves uniqueness if the user
decides to change something in the edited text.
However, overlay can cause issues especially with punctiation,
so the strategy isn't chosen by default when creating a new regex.
Signed-off-by: kingbri <bdashore3@proton.me>
If a regex cannot be parsed, silently return out and don't run the
script. May be a good idea to display a toast message saying the
script didn't run.
Also only reload the chat if a chat is actually loaded.
Signed-off-by: kingbri <bdashore3@proton.me>
Sendas uses a different character's name for messages, so allow
the use of a character name override in the regex match function.
This overrides substituteParams to use a different value.
Signed-off-by: kingbri <bdashore3@proton.me>
Sometimes a user may want to substitute variables in the regex
itself rather than just matching those variables. This can be
optionally enabled in the editor.
In addition, try preventing crashes by checking for undefined
variables or null coalescing.
Signed-off-by: kingbri <bdashore3@proton.me>
If the extension is disabled, don't use any regex formatting. In
addition, wrap all foreach logic into its own function which
reduces the size of all regex injections.
This commit also removes the need for working around static imports
as UI is separate from the engine and is therefore imported at the
same time as other non-static extensions.
Signed-off-by: kingbri <bdashore3@proton.me>
Some extensions are statically imported inside script.js, bypassing
the extension load method. The true method to solve this is using
dynamic imports and undefined checks, but implementing this is
extremely time-consuming.
For now, add the extension_first_load event which fires when
first load is about to start. This changes loading priority to
static -> offline -> online/API.
In addition, initialize the event source earlier since it's more
important than most of the other imports.
Signed-off-by: kingbri <bdashore3@proton.me>
Editing a script can bypass the unique naming system by just renaming
the script to another one. This change ensures that no two script
names can be the same by checking if the existing index and found indices
differ.
If something goes wrong, it would be better to use a filter and a
map and then check the index array length/includes. FindIndex
is used here for efficiency's sake since each array index is unique.
Signed-off-by: kingbri <bdashore3@proton.me>
Fix some UI for flex element wrapping. Text overflow for a script
name is now truncated if it exceeds one line of text. Also fix
how extension settings are laid out to prevent unnecessary
flex resizing.
Signed-off-by: kingbri <bdashore3@proton.me>