Skip to content

Commit

Permalink
Use lz-string to compress & decompress data URLs.
Browse files Browse the repository at this point in the history
  • Loading branch information
jasoncoon committed Apr 23, 2022
1 parent 8fe4b6c commit 7bfa773
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
1 change: 1 addition & 0 deletions index.htm
Original file line number Diff line number Diff line change
Expand Up @@ -690,6 +690,7 @@ <h2 class="accordion-header" id="headingStats">
crossorigin="anonymous"
></script>
<script src="https://unpkg.com/@panzoom/panzoom@4.4.4/dist/panzoom.min.js"></script>
<script language="javascript" src="./js/lz-string.min.js"></script>
<script src="index.js" type="module"></script>
</body>
</html>
13 changes: 9 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,8 @@ function copyLinkToClipboard(element, queryParam, name) {
element.select();
element.setSelectionRange(0, 99999); /* For mobile devices */
const text = element.value;
const data = btoa(text);
const data = LZString.compressToEncodedURIComponent(text);
// const data = btoa(text);
console.log({location: location.toString(), search: location.search, data});
navigator.clipboard.writeText(`${location.toString().replace(location.search, "")}?${queryParam}=${data}`);

Expand Down Expand Up @@ -484,17 +485,21 @@ function parseQueryString() {
let data;
let tabName;
if (coordinates) {
data = atob(coordinates);
// data = atob(coordinates);
data = LZString.decompressFromEncodedURIComponent(coordinates);
textAreaCoordinates.value = data;
tabName = 'coordinates';
parseCoordinates();
} else if (layout) {
data = atob(layout);

// data = atob(layout);
data = LZString.decompressFromEncodedURIComponent(layout);
textAreaLayout.value = data;
tabName = 'layout';
parseLayout();
} else if (pixelblaze) {
data = atob(pixelblaze);
// data = atob(pixelblaze);
data = LZString.decompressFromEncodedURIComponent(pixelblaze);
console.log({data});
textAreaPixelblaze.value = data;
tabName = 'pixelblaze';
Expand Down
1 change: 1 addition & 0 deletions js/lz-string.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 7bfa773

Please sign in to comment.