| 491 | 484 | toastr.success(`Regex script "${regexScript.scriptName}" imported.`); |
| 492 | 485 | } catch (error) { |
| 493 | 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 | + */ |
| 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); |
| 494 | 514 | toastr.error('Invalid JSON file.'); |
| 495 | 515 | return; |
| 496 | 516 | } |