diff --git a/package.json b/package.json index 376ee7105..30a23c620 100644 --- a/package.json +++ b/package.json @@ -47,7 +47,7 @@ "@koa/multer": "3.0.0", "@koa/router": "9.0.1", "@sinonjs/fake-timers": "6.0.1", - "@syuilo/aiscript": "0.8.0", + "@syuilo/aiscript": "0.9.0", "@types/bcryptjs": "2.4.2", "@types/bull": "3.14.0", "@types/cbor": "5.0.0", diff --git a/src/client/components/note.vue b/src/client/components/note.vue index c3a199a80..a359287b4 100644 --- a/src/client/components/note.vue +++ b/src/client/components/note.vue @@ -35,19 +35,19 @@
- +

- +

({{ $t('private') }}) - + RN:
@@ -114,6 +114,7 @@ import { focusPrev, focusNext } from '../scripts/focus'; import { url } from '../config'; import copyToClipboard from '../scripts/copy-to-clipboard'; import { checkWordMute } from '../scripts/check-word-mute'; +import { utils } from '@syuilo/aiscript'; export default Vue.extend({ model: { @@ -246,6 +247,15 @@ export default Vue.extend({ this.connection = this.$root.stream; } + // plugin + if (this.$store.state.noteViewInterruptors.length > 0) { + let result = this.note; + for (const interruptor of this.$store.state.noteViewInterruptors) { + result = utils.valToJs(await interruptor.handler(JSON.parse(JSON.stringify(result)))); + } + this.$emit('updated', Object.freeze(result)); + } + this.muted = await checkWordMute(this.appearNote, this.$store.state.i, this.$store.state.settings.mutedWords); if (this.detail) { diff --git a/src/client/scripts/aiscript/api.ts b/src/client/scripts/aiscript/api.ts index bfbfe8d59..90418fc5c 100644 --- a/src/client/scripts/aiscript/api.ts +++ b/src/client/scripts/aiscript/api.ts @@ -70,6 +70,9 @@ export function createPluginEnv(vm, opts) { 'Plugin:register_note_action': values.FN_NATIVE(([title, handler]) => { vm.$store.commit('registerNoteAction', { pluginId: opts.plugin.id, title: title.value, handler }); }), + 'Plugin:register_note_view_interruptor': values.FN_NATIVE(([handler]) => { + vm.$store.commit('registerNoteViewInterruptor', { pluginId: opts.plugin.id, handler }); + }), 'Plugin:config': values.OBJ(config), }; } diff --git a/src/client/store.ts b/src/client/store.ts index 67dd6ea06..7046e10f9 100644 --- a/src/client/store.ts +++ b/src/client/store.ts @@ -111,6 +111,7 @@ export default () => new Vuex.Store({ postFormActions: [], userActions: [], noteActions: [], + noteViewInterruptors: [], }, getters: { @@ -274,6 +275,14 @@ export default () => new Vuex.Store({ } }); }, + + registerNoteViewInterruptor(state, { pluginId, handler }) { + state.noteViewInterruptors.push({ + handler: (note) => { + return state.pluginContexts.get(pluginId).execFn(handler, [utils.jsToVal(note)]); + } + }); + }, }, actions: { diff --git a/yarn.lock b/yarn.lock index 082f8b4dd..10554e567 100644 --- a/yarn.lock +++ b/yarn.lock @@ -192,10 +192,10 @@ dependencies: "@sinonjs/commons" "^1.7.0" -"@syuilo/aiscript@0.8.0": - version "0.8.0" - resolved "https://registry.yarnpkg.com/@syuilo/aiscript/-/aiscript-0.8.0.tgz#3a895ddd9f5bd5afa1648acb5fd3e6f94f434cbb" - integrity sha512-mrZ3awYf1R81D+OWZctRFiAWUt6xL3A5ovBn2OD8+1hZyX3T7S+awqrhYVLoQPhd/cijz1RT6PE8AEUtuR1J8Q== +"@syuilo/aiscript@0.9.0": + version "0.9.0" + resolved "https://registry.yarnpkg.com/@syuilo/aiscript/-/aiscript-0.9.0.tgz#95f260989ce1d9d4af49f116a4cc0c30360fcdad" + integrity sha512-yv/IQgpcAjyKzd8Q87ANAraISOc7X3SHkXUNc3Asv5ABZ4hx8m62+CnPcrNabIuG2PYRnPGef4ImUpavg6C6Ng== dependencies: autobind-decorator "2.4.0" chalk "4.0.0"