Regex: add export buttons for global and scoped scripts

This commit is contained in:
gk
2025-05-08 01:27:03 +09:00
parent 2650d88606
commit 6df95b98ec
2 changed files with 29 additions and 1 deletions

View File

@@ -21,6 +21,14 @@
<small data-i18n="ext_regex_import_script">Import</small>
</div>
<input type="file" id="import_regex_file" hidden accept="*.json" multiple />
<div id="export_global_regex" class="menu_button menu_button_icon">
<i class="fa-solid fa-file-export"></i>
<small data-i18n="ext_regex_export_global">Export Global</small>
</div>
<div id="export_scoped_regex" class="menu_button menu_button_icon">
<i class="fa-solid fa-file-export"></i>
<small data-i18n="ext_regex_export_scoped">Export Scoped</small>
</div>
</div>
<hr />
<div id="global_scripts_block" class="padding5">

View File

@@ -12,6 +12,8 @@ import { regex_placement, runRegexScript, substitute_find_regex } from './engine
import { t } from '../../i18n.js';
import { accountStorage } from '../../util/AccountStorage.js';
const sanitizeFileName = name => name.replace(/[\s.<>:"/\\|?*\x00-\x1F\x7F]/g, '_').toLowerCase();
/**
* @typedef {import('../../char-data.js').RegexScriptData} RegexScript
*/
@@ -167,7 +169,7 @@ async function loadRegexScripts() {
await saveRegexScript(script, -1, true);
});
scriptHtml.find('.export_regex').on('click', async function () {
const fileName = `${script.scriptName.replace(/[\s.<>:"/\\|?*\x00-\x1F\x7F]/g, '_').toLowerCase()}.json`;
const fileName = `regex-${sanitizeFileName(script.scriptName)}.json`;
const fileData = JSON.stringify(script, null, 4);
download(fileData, fileName, 'application/json');
});
@@ -605,6 +607,24 @@ jQuery(async () => {
$('#import_regex_file').trigger('click');
});
$('#export_global_regex').on('click', async function () {
const regexScripts = extension_settings?.regex ?? [];
if (regexScripts.length) {
const fileName = 'regex-global.json';
const fileData = JSON.stringify(regexScripts, null, 4);
download(fileData, fileName, 'application/json');
}
});
$('#export_scoped_regex').on('click', async function () {
const regexScripts = characters[this_chid]?.data?.extensions?.regex_scripts ?? [];
if (regexScripts.length) {
const fileName = `regex-${sanitizeFileName(characters[this_chid].name)}.json`;
const fileData = JSON.stringify(regexScripts, null, 4);
download(fileData, fileName, 'application/json');
}
});
let sortableDatas = [
{
selector: '#saved_regex_scripts',