From e7da10ae58925c0ca2952af37cef78f2f9b94812 Mon Sep 17 00:00:00 2001 From: syuilo Date: Sun, 12 Apr 2020 19:57:18 +0900 Subject: [PATCH] Resolve #6242 --- src/client/pages/scratchpad.vue | 4 +++- src/client/scripts/create-aiscript-env.ts | 11 ++++++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/client/pages/scratchpad.vue b/src/client/pages/scratchpad.vue index 10292e60c6..63ce5d99d7 100644 --- a/src/client/pages/scratchpad.vue +++ b/src/client/pages/scratchpad.vue @@ -72,7 +72,9 @@ export default Vue.extend({ methods: { async run() { this.logs = []; - const aiscript = new AiScript(createAiScriptEnv(this), { + const aiscript = new AiScript(createAiScriptEnv(this, { + storageKey: 'scratchpad' + }), { in: (q) => { return new Promise(ok => { this.$root.dialog({ diff --git a/src/client/scripts/create-aiscript-env.ts b/src/client/scripts/create-aiscript-env.ts index 75f402e13e..3f7b0c80b5 100644 --- a/src/client/scripts/create-aiscript-env.ts +++ b/src/client/scripts/create-aiscript-env.ts @@ -1,6 +1,6 @@ import { utils, values } from '@syuilo/aiscript'; -export function createAiScriptEnv(vm) { +export function createAiScriptEnv(vm, opts) { return { USER_ID: values.STR(vm.$store.state.i.id), USER_USERNAME: values.STR(vm.$store.state.i.username), @@ -24,5 +24,14 @@ export function createAiScriptEnv(vm) { const res = await vm.$root.api(ep.value, utils.valToJs(param), token || null); return utils.jsToVal(res); }), + 'Mk:save': values.FN_NATIVE(([key, value]) => { + utils.assertString(key); + localStorage.setItem('aiscript:' + opts.storageKey + ':' + key.value, JSON.stringify(utils.valToJs(value))); + return values.NULL; + }), + 'Mk:load': values.FN_NATIVE(([key]) => { + utils.assertString(key); + return utils.jsToVal(JSON.parse(localStorage.getItem('aiscript:' + opts.storageKey + ':' + key.value))); + }), }; }