Closed modulovalue closed 1 year ago
This would be useful. It may have been on a to-do list somewhere for a while, but I never got around to it.
I'm looking into something like https://github.com/pieroxy/lz-string for encoding. It seems like compression would work well in this case because the strings will have relatively few symbols.
I had a quick look at this. Here's my in-progress branch: https://github.com/mdaines/grammophone/compare/spec-search-param
I was going to just use encodeURIComponent
, but grammars may end with .
, meaning that the resulting URL might look like it's at the end of a sentence to some parsers, and they'll strip that from the URL, making the resulting string a parse error. So it seems easiest to use base64 encoding.
The links will probably look like this: https://mdaines.github.io/grammophone/?s=UyAtPiBhIFMgYiAuClMgLT4gLgo= (doesn't work yet)
The links will probably look like this: https://mdaines.github.io/grammophone/?s=UyAtPiBhIFMgYiAuClMgLT4gLgo=
Thank you, this looks perfect to me. I personally also prefer base64 over url encoding.
I've added support for this in d8c631c90b1f5968103e9d24b77545721c74fcc7. I plan to release the change closer to the end of the week.
@mdaines Thank you for adding support for this. The button seems to work, but links that contain a grammar don't seem to work (yet?) e.g. https://mdaines.github.io/grammophone/?s=UyAtPiBTdGFydCAkLgpTdGFydCAtPiBUeXBlIE5hbWUuClN0YXJ0IC0+IE5hbWUuClR5cGUgLT4gaWQgIjwiLgpOYW1lIC0+IGlkICI8Ii4=
Repro:
Maybe it's because the application appends "#/" to the end of the copied url? (https://mdaines.github.io/grammophone/?s=UyAtPiBTdGFydCAkLgpTdGFydCAtPiBUeXBlIE5hbWUuClN0YXJ0IC0+IE5hbWUuClR5cGUgLT4gaWQgIjwiLgpOYW1lIC0+IGlkICI8Ii4=#/)
I think it's because the +
is interpreted as a space character.
Of course, MDN mentions this in the article about URLSearchParams
:
https://developer.mozilla.org/en-US/docs/Web/API/URLSearchParams#preserving_plus_signs
I'll deploy a fix for this.
This should be addressed in b841ef86857971729ce6098566145d3d026ef2ed; the link you provided works now for me.
I can confirm that it also works for me. Thank you!
Hello @mdaines,
First of all, thank you very much for this project!
(If you accept any feature suggestions/requests) I think it would be really great if we could pre-populate the editor with a grammar provided in the url, and share any given grammar by storing it in the url in e.g. a base64 encoded form.
This would allow people to store and share direct links to grammophone and have it be immediately initialized with a grammar. People could also use this to programmatically open grammophone with a grammar from any custom tools that they are building.
One service that does something similar is edotor.