Skip to content

Commit

Permalink
Merge pull request #40 from ongaeshi/feature/set-pixel
Browse files Browse the repository at this point in the history
feat: Implement simple URL encoding for passing code via the 'q2' URL…
  • Loading branch information
ongaeshi authored Jan 25, 2024
2 parents 38dcc5c + c8bc1fb commit b16e516
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,12 @@ const main = async () => {
codeEditor.setValue(LZString.decompressFromEncodedURIComponent(code))
}
}
const q2 = urlParams.get('q2')
if (q2 !== null) {
if (q2 !== "") {
codeEditor.setValue(decodeURIComponent(q2))
}
}

browserVm = new BrowserVm()
await browserVm.createVm(printToOutput)
Expand All @@ -70,7 +76,8 @@ export const runRubyScriptsInHtml = function () {
// Rewrite URL
const queryString = window.location.search;
const urlParams = new URLSearchParams(queryString);
urlParams.set("q", LZString.compressToEncodedURIComponent(codeEditor.getValue()))
urlParams.set("q", LZString.compressToEncodedURIComponent(codeEditor.getValue()));
urlParams.delete("q2");
history.replaceState('', '', "?" + urlParams.toString());

// Clear framebuffer
Expand Down

0 comments on commit b16e516

Please sign in to comment.