Skip to content

Commit

Permalink
Shorter 'share' (#95)
Browse files Browse the repository at this point in the history
* Shorter 'share'

* minize the diff
  • Loading branch information
ldemailly authored Aug 3, 2024
1 parent f5798dc commit 6c11401
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions wasm/grol_wasm.html
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,15 @@
document.getElementById('addParamButton').addEventListener('click', () => {
const paramValue = document.getElementById('input').value
const url = new URL(window.location)
url.searchParams.set('c', paramValue)
window.history.pushState({}, '', url)
function customEscape(str) {
return str.replace(/\+/g, '%2B')
.replace(/ /g, '+')
.replace(/\n/g, '%0A')
.replace(/</g, '%3C')
}
const encodedValue = customEscape(paramValue)
const newUrl = `${url.origin}${url.pathname}?c=${encodedValue}`
window.history.pushState({}, '', newUrl)
});
</script>

Expand Down

0 comments on commit 6c11401

Please sign in to comment.