Skip to content

Commit

Permalink
Add js-compress
Browse files Browse the repository at this point in the history
  • Loading branch information
pavelb committed Nov 23, 2023
1 parent 585837b commit f84fb0b
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
Binary file added .DS_Store
Binary file not shown.
21 changes: 21 additions & 0 deletions js-compress.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<html>
<head>
<style>
html * {
font-family: monospace;
}
</style>
</head>
<body>
<h1>JS Compress</h1>
<p>Compresses Javascript code written using only ascii characters by storing two 8-bit characters in one 16-bit character via a<<8|b</p>
<textarea id="input" rows="6" cols="64" placeholder="Input"></textarea>
<textarea id="output" rows="6" cols="64" placeholder="Output"></textarea>
<script>
const twiceTheDeal = s => s.replace(/../g, c=>String.fromCharCode(c.charCodeAt(0) << 8 | c.charCodeAt(1)));
input.addEventListener('input', _ => {
output.value = "eval(unescape(escape`" + twiceTheDeal(input.value) + "`.replace(/u(..)(..)/g,'u00$1%u00$2')))";
});
</script>
</body>
</html>

0 comments on commit f84fb0b

Please sign in to comment.