upd: Prompt for confirmation when Plugin:open_url is used

This commit is contained in:
Marie 2024-09-15 23:54:31 +02:00
parent 3f37db1a13
commit 9b7301fb2e
No known key found for this signature in database
GPG key ID: 7ADF6C9CD9A28555
4 changed files with 17 additions and 3 deletions

View file

@ -6,7 +6,8 @@
import { ref } from 'vue';
import { Interpreter, Parser, utils, values } from '@syuilo/aiscript';
import { aiScriptReadline, createAiScriptEnv } from '@/scripts/aiscript/api.js';
import { inputText } from '@/os.js';
import * as os from '@/os.js';
import { i18n } from '@/i18n.js';
import { Plugin, noteActions, notePostInterruptors, noteViewInterruptors, postFormActions, userActions, pageViewInterruptors } from '@/store.js';
const parser = new Parser();
@ -91,8 +92,15 @@ function createPluginEnv(opts: { plugin: Plugin; storageKey: string }): Record<s
registerPageViewInterruptor({ pluginId: opts.plugin.id, handler });
}),
'Plugin:open_url': values.FN_NATIVE(([url]) => {
utils.assertString(url);
window.open(url.value, '_blank', 'noopener');
(async () => {
utils.assertString(url);
const { canceled } = await os.confirm({
type: 'question',
text: i18n.tsx.confirmRemoteUrl({x: url.value}),
});
if (canceled) return;
window.open(url.value, '_blank', 'noopener');
})();
}),
'Plugin:config': values.OBJ(config),
};