Regex: allow multiple definitions in a single file

2650d8860641386452cef36290ed94150814c76f

gk <gkpyon@gmail.com>

1 files changed, +30 -10Showing whitespace changes
public/scripts/extensions/regex/index.js+30 -10
@@ -459,19 +459,12 @@ async function toggleRegexCallback(args, scriptName) {
459459}
460460
461461/**
462462 * Performs the import of the regex fileobject.
463463 * @param {FileObject} fileregexScript Input fileobject
464464 * @param {boolean} isScoped Is the script scoped to a character?
465465 */
466466async function onRegexImportFileChangeonRegexImportObjectChange(fileregexScript, isScoped) {
467- if (!file) {
468- toastr.error('No file provided.');
469- return;
470- }
471-
472467 try {
473- const fileText = await getFileText(file);
474- const regexScript = JSON.parse(fileText);
475468 if (!regexScript.scriptName) {
476469 throw new Error('No script name provided.');
477470 }
@@ -491,6 +484,33 @@ async function onRegexImportFileChange(file, isScoped) {
491484 toastr.success(`Regex script "${regexScript.scriptName}" imported.`);
492485 } catch (error) {
493486 console.log(error);
487+ toastr.error('Invalid regex object.');
488+ return;
489+ }
490+}
491+
492+/**
493+ * Performs the import of the regex file.
494+ * @param {File} file Input file
495+ * @param {boolean} isScoped Is the script scoped to a character?
496+ */
497+async function onRegexImportFileChange(file, isScoped) {
498+ if (!file) {
499+ toastr.error('No file provided.');
500+ return;
501+ }
502+
503+ try {
504+ const regexScripts = JSON.parse(await getFileText(file));
505+ if (Array.isArray(regexScripts)) {
506+ for (const regexScript of regexScripts) {
507+ await onRegexImportObjectChange(regexScript, isScoped);
508+ }
509+ } else {
510+ await onRegexImportObjectChange(regexScripts, isScoped);
511+ }
512+ } catch (error) {
513+ console.log(error);
494514 toastr.error('Invalid JSON file.');
495515 return;
496516 }