Regex: add export buttons for global and scoped scripts
| @@ -21,6 +21,14 @@ | ||
| 21 | 21 | <small data-i18n="ext_regex_import_script">Import</small> |
| 22 | 22 | </div> |
| 23 | 23 | <input type="file" id="import_regex_file" hidden accept="*.json" multiple /> |
| 24 | + <div id="export_global_regex" class="menu_button menu_button_icon"> | |
| 25 | + <i class="fa-solid fa-file-export"></i> | |
| 26 | + <small data-i18n="ext_regex_export_global">Export Global</small> | |
| 27 | + </div> | |
| 28 | + <div id="export_scoped_regex" class="menu_button menu_button_icon"> | |
| 29 | + <i class="fa-solid fa-file-export"></i> | |
| 30 | + <small data-i18n="ext_regex_export_scoped">Export Scoped</small> | |
| 31 | + </div> | |
| 24 | 32 | </div> |
| 25 | 33 | <hr /> |
| 26 | 34 | <div id="global_scripts_block" class="padding5"> |
| @@ -12,6 +12,8 @@ import { regex_placement, runRegexScript, substitute_find_regex } from './engine | ||
| 12 | 12 | import { t } from '../../i18n.js'; |
| 13 | 13 | import { accountStorage } from '../../util/AccountStorage.js'; |
| 14 | 14 | |
| 15 | +const sanitizeFileName = name => name.replace(/[\s.<>:"/\\|?*\x00-\x1F\x7F]/g, '_').toLowerCase(); | |
| 16 | + | |
| 15 | 17 | /** |
| 16 | 18 | * @typedef {import('../../char-data.js').RegexScriptData} RegexScript |
| 17 | 19 | */ |
| @@ -167,7 +169,7 @@ async function loadRegexScripts() { | ||
| 167 | 169 | await saveRegexScript(script, -1, true); |
| 168 | 170 | }); |
| 169 | 171 | scriptHtml.find('.export_regex').on('click', async function () { |
| 170 | - const fileName = `${script.scriptName.replace(/[\s.<>:"/\\|?*\x00-\x1F\x7F]/g, '_').toLowerCase()}.json`; | |
| 172 | + const fileName = `regex-${sanitizeFileName(script.scriptName)}.json`; | |
| 171 | 173 | const fileData = JSON.stringify(script, null, 4); |
| 172 | 174 | download(fileData, fileName, 'application/json'); |
| 173 | 175 | }); |
| @@ -605,6 +607,24 @@ jQuery(async () => { | ||
| 605 | 607 | $('#import_regex_file').trigger('click'); |
| 606 | 608 | }); |
| 607 | 609 | |
| 610 | + $('#export_global_regex').on('click', async function () { | |
| 611 | + const regexScripts = extension_settings?.regex ?? []; | |
| 612 | + if (regexScripts.length) { | |
| 613 | + const fileName = 'regex-global.json'; | |
| 614 | + const fileData = JSON.stringify(regexScripts, null, 4); | |
| 615 | + download(fileData, fileName, 'application/json'); | |
| 616 | + } | |
| 617 | + }); | |
| 618 | + | |
| 619 | + $('#export_scoped_regex').on('click', async function () { | |
| 620 | + const regexScripts = characters[this_chid]?.data?.extensions?.regex_scripts ?? []; | |
| 621 | + if (regexScripts.length) { | |
| 622 | + const fileName = `regex-${sanitizeFileName(characters[this_chid].name)}.json`; | |
| 623 | + const fileData = JSON.stringify(regexScripts, null, 4); | |
| 624 | + download(fileData, fileName, 'application/json'); | |
| 625 | + } | |
| 626 | + }); | |
| 627 | + | |
| 608 | 628 | let sortableDatas = [ |
| 609 | 629 | { |
| 610 | 630 | selector: '#saved_regex_scripts', |