Skip to content

Commit

Permalink
feat: Implement compression in share URL (#34)
Browse files Browse the repository at this point in the history
* feat: Implement compression

* fix: Don't use longURL at all

* clear hash when sharing compresed url
  • Loading branch information
strazto authored Mar 14, 2024
1 parent 775ca09 commit 9f506fa
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,12 @@
</div>

<script src="ace/ace.js" type="text/javascript" charset="utf-8"></script>
<script
src="https://cdnjs.cloudflare.com/ajax/libs/lz-string/1.5.0/lz-string.min.js"
integrity="sha512-qtX0GLM3qX8rxJN1gyDfcnMFFrKvixfoEOwbBib9VafR5vbChV5LeE5wSI/x+IlCkTY5ZFddFDCCfaVJJNnuKQ=="
crossorigin="anonymous"
referrerpolicy="no-referrer"
></script>
<script>
(function (document) {
//http://stackoverflow.com/a/10372280/398634
Expand Down Expand Up @@ -296,7 +302,12 @@
var result = JSON.parse(this.responseText);
shareURLEl.value = result.link;
} else {
shareURLEl.value = longUrl.toString();
const compressedContent = LZString.compressToEncodedURIComponent(editor.getSession().getDocument().getValue());
const compressedUrl = new URL(location.href);
compressedUrl.searchParams.append("compressed", compressedContent);
compressedUrl.hash = "";

shareURLEl.value = compressedUrl.toString();
}
};
}
Expand Down Expand Up @@ -491,6 +502,7 @@
renderGraph();
} else if (params.has('compressed')) {
const compressed = params.get('compressed');
editor.getSession().setValue(LZString.decompressFromEncodedURIComponent(compressed));
} else if (params.has('url')) {
const url = params.get('url');
let ok = false;
Expand Down

0 comments on commit 9f506fa

Please sign in to comment.