summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorElizabeth Hunt <elizabeth.hunt@simponic.xyz>2023-11-17 12:12:57 -0700
committerElizabeth Hunt <elizabeth.hunt@simponic.xyz>2023-11-17 12:12:57 -0700
commit57a4d439847bf3d63513b2443dfdf1eca5ecbb02 (patch)
tree1e533860b2d3a6b69dd403887b6a796ff221475c
parenta54a7ba7c95965268d7a2a3c64a6a6c599fdb9da (diff)
downloadsimponic.xyz-57a4d439847bf3d63513b2443dfdf1eca5ecbb02.tar.gz
simponic.xyz-57a4d439847bf3d63513b2443dfdf1eca5ecbb02.zip
add copy state button
-rw-r--r--godel/index.html3
-rw-r--r--godel/js/main.js14
2 files changed, 15 insertions, 2 deletions
diff --git a/godel/index.html b/godel/index.html
index f8e8dad..f74a48e 100644
--- a/godel/index.html
+++ b/godel/index.html
@@ -54,7 +54,8 @@
Y &lt;- Y + 1
GOTO C1</textarea>
<div>
- <button id="compile">Compile</button>
+ <button id="compile">Compile</button> <button id=
+ "copy">Copy</button>
</div>
<div>
<span style="margin-left: 0.5rem" id=
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", () => {