Skip to content

Commit

Permalink
fix: add save action from old repo (#81)
Browse files Browse the repository at this point in the history
  • Loading branch information
j4k0xb committed May 18, 2024
1 parent 0e061d9 commit 5e66a11
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions apps/playground/src/components/MonacoEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,34 @@ export default function MonacoEditor(props: Props) {
},
});

const saveAction = editor.addAction({
id: 'editor.action.save',
label: 'Save',
keybindings: [monaco.KeyMod.CtrlCmd | monaco.KeyCode.KeyS],
run(editor) {
const code = editor.getValue();
if (code === '') return;

const blob = new Blob([code], {
type: 'application/javascript;charset=utf-8',
});
const url = URL.createObjectURL(blob);
const link = document.createElement('a');

link.setAttribute('href', url);
link.setAttribute(
'download',
`deobfuscated-${new Date().toISOString()}.js`,
);
link.style.display = 'none';
document.body.appendChild(link);
link.click();
document.body.removeChild(link);

URL.revokeObjectURL(url);
},
});

const evalAction = registerEvalSelection(editor);

const commandPalette = editor.getAction('editor.action.quickCommand')!;
Expand All @@ -111,6 +139,7 @@ export default function MonacoEditor(props: Props) {
placeholder.dispose();
deobfuscateAction.dispose();
evalAction.dispose();
saveAction.dispose();
});
});

Expand Down

0 comments on commit 5e66a11

Please sign in to comment.