|
@@ -15,8 +15,12 @@ window.onload = () => {
|
|
|
|
|
|
const updateCode = () => {
|
|
|
const code = editor.state.doc.toString();
|
|
|
+ const data = JSON.stringify({
|
|
|
+ 'source': code,
|
|
|
+ 'seed': Number(seed.value),
|
|
|
+ });
|
|
|
// update the URL hash
|
|
|
- location.hash = '#' + encodeURIComponent(code);
|
|
|
+ location.hash = '#' + encodeURIComponent(data);
|
|
|
// run the code
|
|
|
updateOutput(code);
|
|
|
|
|
@@ -44,9 +48,20 @@ window.onload = () => {
|
|
|
|
|
|
if (location.hash) {
|
|
|
const encoded = location.hash.substring(1);
|
|
|
- editor.dispatch({
|
|
|
- changes: {from: 0, insert: decodeURIComponent(encoded)}
|
|
|
- });
|
|
|
+
|
|
|
+ try {
|
|
|
+ const data = JSON.parse(decodeURIComponent(encoded));
|
|
|
+ editor.dispatch({
|
|
|
+ changes: {from: 0, insert: data.source}
|
|
|
+ });
|
|
|
+ seed.value = Number(data.seed);
|
|
|
+ console.log(`Setting seed value to ${seed.value}`);
|
|
|
+ } catch (exn) {
|
|
|
+ editor.dispatch({
|
|
|
+ changes: {from: 0, insert: sources['simple']}
|
|
|
+ });
|
|
|
+ seed.value = 12345;
|
|
|
+ }
|
|
|
} else {
|
|
|
editor.dispatch({
|
|
|
changes: {from: 0, insert: sources['simple']}
|
|
@@ -59,12 +74,12 @@ window.onload = () => {
|
|
|
};
|
|
|
|
|
|
seed.onchange = () => {
|
|
|
- updateOutput(editor.state.doc.toString());
|
|
|
+ updateCode();
|
|
|
}
|
|
|
|
|
|
run.onclick = () => {
|
|
|
seed.value = Math.floor(Math.random() * 0xffffffff);
|
|
|
- updateOutput(editor.state.doc.toString());
|
|
|
+ updateCode();
|
|
|
}
|
|
|
});
|
|
|
};
|