This commit is contained in:
タービン 2023-03-15 10:44:24 +09:00 committed by GitHub
parent c05c504c86
commit 42833cd921
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 34 additions and 3 deletions

View file

@ -1,7 +1,7 @@
import { Interpreter, Parser, utils, values } from '@syuilo/aiscript';
import { createAiScriptEnv } from '@/scripts/aiscript/api';
import { inputText } from '@/os';
import { Plugin, noteActions, notePostInterruptors, noteViewInterruptors, postFormActions, userActions } from '@/store';
import { Plugin, noteActions, notePostInterruptors, noteViewInterruptors, postFormActions, userActions, pageViewInterruptors } from '@/store';
const parser = new Parser();
const pluginContexts = new Map<string, Interpreter>();
@ -80,6 +80,9 @@ function createPluginEnv(opts: { plugin: Plugin; storageKey: string }): Record<s
'Plugin:register_note_post_interruptor': values.FN_NATIVE(([handler]) => {
registerNotePostInterruptor({ pluginId: opts.plugin.id, handler });
}),
'Plugin:register_page_view_interruptor': values.FN_NATIVE(([handler]) => {
registerPageViewInterruptor({ pluginId: opts.plugin.id, handler });
}),
'Plugin:open_url': values.FN_NATIVE(([url]) => {
utils.assertString(url);
window.open(url.value, '_blank');
@ -156,3 +159,15 @@ function registerNotePostInterruptor({ pluginId, handler }): void {
},
});
}
function registerPageViewInterruptor({ pluginId, handler }): void {
pageViewInterruptors.push({
handler: async (page) => {
const pluginContext = pluginContexts.get(pluginId);
if (!pluginContext) {
return;
}
return utils.valToJs(await pluginContext.execFn(handler, [utils.jsToVal(page)]));
},
});
}