Require single quotes

This commit is contained in:
valadaptive
2023-12-02 13:04:51 -05:00
parent a06f1e8ad6
commit a37f874e38
76 changed files with 4135 additions and 4134 deletions

View File

@ -1,16 +1,16 @@
import { callPopup, getCurrentChatId, reloadCurrentChat, saveSettingsDebounced } from "../../../script.js";
import { extension_settings } from "../../extensions.js";
import { registerSlashCommand } from "../../slash-commands.js";
import { getSortableDelay, uuidv4 } from "../../utils.js";
import { resolveVariable } from "../../variables.js";
import { regex_placement, runRegexScript } from "./engine.js";
import { callPopup, getCurrentChatId, reloadCurrentChat, saveSettingsDebounced } from '../../../script.js';
import { extension_settings } from '../../extensions.js';
import { registerSlashCommand } from '../../slash-commands.js';
import { getSortableDelay, uuidv4 } from '../../utils.js';
import { resolveVariable } from '../../variables.js';
import { regex_placement, runRegexScript } from './engine.js';
async function saveRegexScript(regexScript, existingScriptIndex) {
// If not editing
// Is the script name undefined or empty?
if (!regexScript.scriptName) {
toastr.error(`Could not save regex script: The script name was undefined or empty!`);
toastr.error('Could not save regex script: The script name was undefined or empty!');
return;
}
@ -32,12 +32,12 @@ async function saveRegexScript(regexScript, existingScriptIndex) {
// Is a find regex present?
if (regexScript.findRegex.length === 0) {
toastr.warning(`This regex script will not work, but was saved anyway: A find regex isn't present.`);
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.warning(`This regex script will not work, but was saved anyway: One "Affects" checkbox must be selected!`);
toastr.warning('This regex script will not work, but was saved anyway: One "Affects" checkbox must be selected!');
}
if (existingScriptIndex !== -1) {
@ -69,45 +69,45 @@ async function deleteRegexScript({ existingId }) {
}
async function loadRegexScripts() {
$("#saved_regex_scripts").empty();
$('#saved_regex_scripts').empty();
const scriptTemplate = $(await $.get("scripts/extensions/regex/scriptTemplate.html"));
const scriptTemplate = $(await $.get('scripts/extensions/regex/scriptTemplate.html'));
extension_settings.regex.forEach((script) => {
// Have to clone here
const scriptHtml = scriptTemplate.clone();
scriptHtml.attr('id', uuidv4());
scriptHtml.find('.regex_script_name').text(script.scriptName);
scriptHtml.find('.disable_regex').prop("checked", script.disabled ?? false)
scriptHtml.find('.disable_regex').prop('checked', script.disabled ?? false)
.on('input', function () {
script.disabled = !!$(this).prop("checked");
script.disabled = !!$(this).prop('checked');
saveSettingsDebounced();
});
scriptHtml.find('.regex-toggle-on').on('click', function () {
scriptHtml.find('.disable_regex').prop("checked", true).trigger('input');
scriptHtml.find('.disable_regex').prop('checked', true).trigger('input');
});
scriptHtml.find('.regex-toggle-off').on('click', function () {
scriptHtml.find('.disable_regex').prop("checked", false).trigger('input');
scriptHtml.find('.disable_regex').prop('checked', false).trigger('input');
});
scriptHtml.find('.edit_existing_regex').on('click', async function () {
await onRegexEditorOpenClick(scriptHtml.attr("id"));
await onRegexEditorOpenClick(scriptHtml.attr('id'));
});
scriptHtml.find('.delete_regex').on('click', async function () {
const confirm = await callPopup("Are you sure you want to delete this regex script?", "confirm");
const confirm = await callPopup('Are you sure you want to delete this regex script?', 'confirm');
if (!confirm) {
return;
}
await deleteRegexScript({ existingId: scriptHtml.attr("id") });
await deleteRegexScript({ existingId: scriptHtml.attr('id') });
});
$("#saved_regex_scripts").append(scriptHtml);
$('#saved_regex_scripts').append(scriptHtml);
});
}
async function onRegexEditorOpenClick(existingId) {
const editorHtml = $(await $.get("scripts/extensions/regex/editor.html"));
const editorHtml = $(await $.get('scripts/extensions/regex/editor.html'));
// If an ID exists, fill in all the values
let existingScriptIndex = -1;
@ -117,92 +117,92 @@ async function onRegexEditorOpenClick(existingId) {
if (existingScriptIndex !== -1) {
const existingScript = extension_settings.regex[existingScriptIndex];
if (existingScript.scriptName) {
editorHtml.find(`.regex_script_name`).val(existingScript.scriptName);
editorHtml.find('.regex_script_name').val(existingScript.scriptName);
} else {
toastr.error("This script doesn't have a name! Please delete it.")
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('.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);
.find('input[name="disabled"]')
.prop('checked', existingScript.disabled ?? false);
editorHtml
.find(`input[name="only_format_display"]`)
.prop("checked", existingScript.markdownOnly ?? false);
.find('input[name="only_format_display"]')
.prop('checked', existingScript.markdownOnly ?? false);
editorHtml
.find(`input[name="only_format_prompt"]`)
.prop("checked", existingScript.promptOnly ?? false);
.find('input[name="only_format_prompt"]')
.prop('checked', existingScript.promptOnly ?? false);
editorHtml
.find(`input[name="run_on_edit"]`)
.prop("checked", existingScript.runOnEdit ?? false);
.find('input[name="run_on_edit"]')
.prop('checked', existingScript.runOnEdit ?? false);
editorHtml
.find(`input[name="substitute_regex"]`)
.prop("checked", existingScript.substituteRegex ?? false);
.find('input[name="substitute_regex"]')
.prop('checked', existingScript.substituteRegex ?? false);
editorHtml
.find(`select[name="replace_strategy_select"]`)
.find('select[name="replace_strategy_select"]')
.val(existingScript.replaceStrategy ?? 0);
existingScript.placement.forEach((element) => {
editorHtml
.find(`input[name="replace_position"][value="${element}"]`)
.prop("checked", true);
.prop('checked', true);
});
}
} else {
editorHtml
.find(`input[name="only_format_display"]`)
.prop("checked", true);
.find('input[name="only_format_display"]')
.prop('checked', true);
editorHtml
.find(`input[name="run_on_edit"]`)
.prop("checked", true);
.find('input[name="run_on_edit"]')
.prop('checked', true);
editorHtml
.find(`input[name="replace_position"][value="1"]`)
.prop("checked", true);
.find('input[name="replace_position"][value="1"]')
.prop('checked', true);
}
const popupResult = await callPopup(editorHtml, "confirm", undefined, { okButton: "Save" });
const popupResult = await callPopup(editorHtml, 'confirm', undefined, { okButton: 'Save' });
if (popupResult) {
const newRegexScript = {
scriptName: editorHtml.find(".regex_script_name").val(),
findRegex: editorHtml.find(".find_regex").val(),
replaceString: editorHtml.find(".regex_replace_string").val(),
trimStrings: editorHtml.find(".regex_trim_strings").val().split("\n").filter((e) => e.length !== 0) || [],
scriptName: editorHtml.find('.regex_script_name').val(),
findRegex: editorHtml.find('.find_regex').val(),
replaceString: editorHtml.find('.regex_replace_string').val(),
trimStrings: editorHtml.find('.regex_trim_strings').val().split('\n').filter((e) => e.length !== 0) || [],
placement:
editorHtml
.find(`input[name="replace_position"]`)
.filter(":checked")
.find('input[name="replace_position"]')
.filter(':checked')
.map(function () { return parseInt($(this).val()) })
.get()
.filter((e) => !isNaN(e)) || [],
disabled:
editorHtml
.find(`input[name="disabled"]`)
.prop("checked"),
.find('input[name="disabled"]')
.prop('checked'),
markdownOnly:
editorHtml
.find(`input[name="only_format_display"]`)
.prop("checked"),
.find('input[name="only_format_display"]')
.prop('checked'),
promptOnly:
editorHtml
.find(`input[name="only_format_prompt"]`)
.prop("checked"),
.find('input[name="only_format_prompt"]')
.prop('checked'),
runOnEdit:
editorHtml
.find(`input[name="run_on_edit"]`)
.prop("checked"),
.find('input[name="run_on_edit"]')
.prop('checked'),
substituteRegex:
editorHtml
.find(`input[name="substitute_regex"]`)
.prop("checked"),
.find('input[name="substitute_regex"]')
.prop('checked'),
replaceStrategy:
parseInt(editorHtml
.find(`select[name="replace_strategy_select"]`)
.find(`:selected`)
.find('select[name="replace_strategy_select"]')
.find(':selected')
.val()) ?? 0
};
@ -252,7 +252,7 @@ function migrateSettings() {
*/
function runRegexCallback(args, value) {
if (!args.name) {
toastr.warning("No regex script name provided.");
toastr.warning('No regex script name provided.');
return value;
}
@ -282,13 +282,13 @@ jQuery(async () => {
}
// Manually disable the extension since static imports auto-import the JS file
if (extension_settings.disabledExtensions.includes("regex")) {
if (extension_settings.disabledExtensions.includes('regex')) {
return;
}
const settingsHtml = await $.get("scripts/extensions/regex/dropdown.html");
$("#extensions_settings2").append(settingsHtml);
$("#open_regex_editor").on("click", function () {
const settingsHtml = await $.get('scripts/extensions/regex/dropdown.html');
$('#extensions_settings2').append(settingsHtml);
$('#open_regex_editor').on('click', function () {
onRegexEditorOpenClick(false);
});
@ -297,7 +297,7 @@ jQuery(async () => {
stop: function () {
let newScripts = [];
$('#saved_regex_scripts').children().each(function () {
const scriptName = $(this).find(".regex_script_name").text();
const scriptName = $(this).find('.regex_script_name').text();
const existingScript = extension_settings.regex.find((e) => e.scriptName === scriptName);
if (existingScript) {
newScripts.push(existingScript);
@ -307,13 +307,13 @@ jQuery(async () => {
extension_settings.regex = newScripts;
saveSettingsDebounced();
console.debug("Regex scripts reordered");
console.debug('Regex scripts reordered');
// TODO: Maybe reload regex scripts after move
},
});
await loadRegexScripts();
$("#saved_regex_scripts").sortable("enable");
$('#saved_regex_scripts').sortable('enable');
registerSlashCommand('regex', runRegexCallback, [], '(name=scriptName [input]) runs a Regex extension script by name on the provided string. The script must be enabled.', true, true);
});