From 57a4d439847bf3d63513b2443dfdf1eca5ecbb02 Mon Sep 17 00:00:00 2001 From: Elizabeth Hunt Date: Fri, 17 Nov 2023 12:12:57 -0700 Subject: add copy state button --- godel/js/main.js | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'godel/js/main.js') diff --git a/godel/js/main.js b/godel/js/main.js index 898c558..9092d2c 100644 --- a/godel/js/main.js +++ b/godel/js/main.js @@ -77,6 +77,18 @@ const compiledEditorEl = CodeMirror.fromTextArea(compiledEl, codeMirrorConfig); const godelSequenceEl = document.getElementById("godel_sequence"); const godelNumberEl = document.getElementById("godel_number"); const godelNumberComputeBtn = document.getElementById("godel_number_comp"); +const copyStateButton = document.getElementById("copy"); + +// hackily copy the program state and put it in the clipboard +copyStateButton.addEventListener("click", () => { + const instructions = btoa(instructionsEditorEl.getValue()); + + navigator.clipboard + .writeText( + window.location.href.split("?")[0] + `?instructions=${instructions}` + ) + .then(() => alert("copied to clipboard")); +}); state.subscribe((msg) => { if (msg.type == MESSAGES.COMPILE_RESULT) { @@ -146,7 +158,7 @@ state.subscribe((msg) => { const urlParams = new URLSearchParams(window.location.search); if (urlParams.get("instructions")) { - editorEl.setValue(atob(urlParams.get("instructions"))); + instructionsEditorEl.setValue(atob(urlParams.get("instructions"))); } compileButton.addEventListener("click", () => { -- cgit v1.2.3-70-g09d2