| 607 | 607 | $('#import_regex_file').trigger('click'); |
| 608 | 608 | }); |
| 609 | 609 | |
| 610 | | - $('#export_global_regex').on('click', async function () { |
| 610 | + function getSelectedScripts() { |
| 611 | | - const regexScripts = extension_settings?.regex ?? []; |
| 611 | + const scripts = getRegexScripts(); |
| 612 | | - if (regexScripts.length) { |
| 612 | + const selector = '#regex_container .regex-script-label:has(.regex_bulk_checkbox:checked)'; |
| 613 | | - const fileName = 'regex-global.json'; |
| 613 | + const selectedIds = Array.from(document.querySelectorAll(selector)).map(e => e.getAttribute('id')).filter(id => id); |
| 614 | | - const fileData = JSON.stringify(regexScripts, null, 4); |
| 614 | + return scripts.filter(script => selectedIds.includes(script.id)); |
| 615 | | - download(fileData, fileName, 'application/json'); |
| 615 | + } |
| 616 | + |
| 617 | + $('#bulk_enable_regex').on('click', async function () { |
| 618 | + const scripts = getSelectedScripts().filter(script => script.disabled); |
| 619 | + if (scripts.length === 0) { |
| 620 | + toastr.warning(t`No regex scripts selected for enabling.`); |
| 621 | + return; |
| 616 | 622 | } |
| 623 | + for (const script of scripts) { |
| 624 | + script.disabled = false; |
| 625 | + } |
| 626 | + saveSettingsDebounced(); |
| 627 | + await loadRegexScripts(); |
| 617 | 628 | }); |
| 618 | 629 | |
| 619 | 630 | $('#export_scoped_regexbulk_disable_regex').on('click', async function () { |
| 620 | | - const regexScripts = characters[this_chid]?.data?.extensions?.regex_scripts ?? []; |
| 631 | + const scripts = getSelectedScripts().filter(script => !script.disabled); |
| 621 | 632 | if (regexScriptsscripts.length === 0) { |
| 622 | | - const fileName = `regex-${sanitizeFileName(characters[this_chid].name)}.json`; |
| 633 | + toastr.warning(t`No regex scripts selected for disabling.`); |
| 623 | | - const fileData = JSON.stringify(regexScripts, null, 4); |
| 634 | + return; |
| 624 | | - download(fileData, fileName, 'application/json'); |
| 625 | 635 | } |
| 636 | + for (const script of scripts) { |
| 637 | + script.disabled = true; |
| 638 | + } |
| 639 | + saveSettingsDebounced(); |
| 640 | + await loadRegexScripts(); |
| 641 | + }); |
| 642 | + |
| 643 | + $('#bulk_delete_regex').on('click', async function () { |
| 644 | + const scripts = getSelectedScripts(); |
| 645 | + if (scripts.length === 0) { |
| 646 | + toastr.warning(t`No regex scripts selected for deletion.`); |
| 647 | + return; |
| 648 | + } |
| 649 | + const confirm = await callGenericPopup('Are you sure you want to delete the selected regex scripts?', POPUP_TYPE.CONFIRM); |
| 650 | + if (!confirm) { |
| 651 | + return; |
| 652 | + } |
| 653 | + for (const script of scripts) { |
| 654 | + const isScoped = characters[this_chid]?.data?.extensions?.regex_scripts?.some(s => s.id === script.id); |
| 655 | + await deleteRegexScript({ id: script.id, isScoped: isScoped }); |
| 656 | + } |
| 657 | + await reloadCurrentChat(); |
| 658 | + saveSettingsDebounced(); |
| 659 | + }); |
| 660 | + |
| 661 | + $('#bulk_export_regex').on('click', async function () { |
| 662 | + const scripts = getSelectedScripts(); |
| 663 | + if (scripts.length === 0) { |
| 664 | + toastr.warning(t`No regex scripts selected for export.`); |
| 665 | + return; |
| 666 | + } |
| 667 | + const fileName = `regex-${new Date().toISOString()}.json`; |
| 668 | + const fileData = JSON.stringify(scripts, null, 4); |
| 669 | + download(fileData, fileName, 'application/json'); |
| 670 | + await loadRegexScripts(); |
| 626 | 671 | }); |
| 627 | 672 | |
| 628 | 673 | let sortableDatas = [ |