From aa1bf272413e1030fe7ecfb64c1ca2f1da22473a Mon Sep 17 00:00:00 2001 From: ojack Date: Thu, 7 Apr 2022 14:25:44 +0200 Subject: [PATCH] save code and image --- frontend/web-editor/public/bundle.js | 13 +++++++++++++ frontend/web-editor/src/store.js | 13 +++++++++++++ 2 files changed, 26 insertions(+) diff --git a/frontend/web-editor/public/bundle.js b/frontend/web-editor/public/bundle.js index c5a805d..7a93808 100644 --- a/frontend/web-editor/public/bundle.js +++ b/frontend/web-editor/public/bundle.js @@ -47284,6 +47284,19 @@ module.exports = function store(state, emitter) { emitter.on('screencap', () => { screencap() + const editor = state.editor.editor + const text = editor.getValue() + const data = new Blob([text], {type: 'text/plain'}); + const a = document.createElement('a') + a.style.display = 'none' + let d = new Date() + a.download = `hydra-${d.getFullYear()}-${d.getMonth() + 1}-${d.getDate()}-${d.getHours()}.${d.getMinutes()}.${d.getSeconds()}.js` + a.href = URL.createObjectURL(data) + a.click() + + setTimeout(() => { + window.URL.revokeObjectURL(a.href); + }, 300); }) emitter.on('editor:randomize', function (evt) { diff --git a/frontend/web-editor/src/store.js b/frontend/web-editor/src/store.js index 375ddb2..0025984 100644 --- a/frontend/web-editor/src/store.js +++ b/frontend/web-editor/src/store.js @@ -53,6 +53,19 @@ module.exports = function store(state, emitter) { emitter.on('screencap', () => { screencap() + const editor = state.editor.editor + const text = editor.getValue() + const data = new Blob([text], {type: 'text/plain'}); + const a = document.createElement('a') + a.style.display = 'none' + let d = new Date() + a.download = `hydra-${d.getFullYear()}-${d.getMonth() + 1}-${d.getDate()}-${d.getHours()}.${d.getMinutes()}.${d.getSeconds()}.js` + a.href = URL.createObjectURL(data) + a.click() + + setTimeout(() => { + window.URL.revokeObjectURL(a.href); + }, 300); }) emitter.on('editor:randomize', function (evt) {