Regex: allow multiple definitions in a single file

2650d8860641386452cef36290ed94150814c76f

gk <gkpyon@gmail.com>

1 files changed, +30 -10Ignore whitespace
public/scripts/extensions/regex/index.js+30 -10
@@ -459,19 +459,12 @@ async function toggleRegexCallback(args, scriptName) {
459}459}
460460
461/**461/**
462 * Performs the import of the regex file.462 * Performs the import of the regex object.
463 * @param {File} file Input file463 * @param {Object} regexScript Input object
464 * @param {boolean} isScoped Is the script scoped to a character?464 * @param {boolean} isScoped Is the script scoped to a character?
465 */465 */
466async function onRegexImportFileChange(file, isScoped) {466async function onRegexImportObjectChange(regexScript, isScoped) {
467 if (!file) {
468 toastr.error('No file provided.');
469 return;
470 }
471
472 try {467 try {
473 const fileText = await getFileText(file);
474 const regexScript = JSON.parse(fileText);
475 if (!regexScript.scriptName) {468 if (!regexScript.scriptName) {
476 throw new Error('No script name provided.');469 throw new Error('No script name provided.');
477 }470 }
@@ -491,6 +484,33 @@ async function onRegexImportFileChange(file, isScoped) {
491 toastr.success(`Regex script "${regexScript.scriptName}" imported.`);484 toastr.success(`Regex script "${regexScript.scriptName}" imported.`);
492 } catch (error) {485 } catch (error) {
493 console.log(error);486 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 */
497async 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);
494 toastr.error('Invalid JSON file.');514 toastr.error('Invalid JSON file.');
495 return;515 return;
496 }516 }