summaryrefslogtreecommitdiff
path: root/packages/frontend/src/plugin.ts
diff options
context:
space:
mode:
Diffstat (limited to 'packages/frontend/src/plugin.ts')
-rw-r--r--packages/frontend/src/plugin.ts17
1 files changed, 16 insertions, 1 deletions
diff --git a/packages/frontend/src/plugin.ts b/packages/frontend/src/plugin.ts
index a1a36480fd..9b6b01780c 100644
--- a/packages/frontend/src/plugin.ts
+++ b/packages/frontend/src/plugin.ts
@@ -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)]));
+ },
+ });
+}