- Author:
- Kyle Simpson
- Twitter:
- @
- GitHub:
- Facebook:
- Google+:
- +
- Reddit:
- /r/
- Pouet:
- Website:
- blog.getify.com
- Compo:
- classic
- Demo link:
- https://js1k.com/2010-first/demo/508
- Shortlink:
- https://js1k.com/508
- Blog post:
- please update here!
- Bytes:
- 1024
- Chars:
- 1024
- Submission
a="D=docume;C,hi=[],d,j,k=31,1,e=25,,g,l,m=[0,0,5,4,4];;g=cubs(f,e(!match(/\\/|\\\\/)l=Y=RegExp(g/([.*+?|$^\\(\\)[\\]{}])/\\\\$1,'g) ;(((Z=m[e])&&l>=Z)||l>=3&&(b=SinfromCharCode(a++))!b));else b=0;bi.unsht(b+gYb=;coinue}f>=c -1-ee>2;e--;coinue}}}f++/\"/g)&&(b=SinfromCharCode(a++))!b));else b=0;bi.unsht(b+'\\\\\"'/\"/g)}}j='\"'+/\\\\/\\\\\\\\/\"/\\\\\"'\";for(b in \"'+i.join(\"/\"\"plit(\"/\"))aRegExp(c[b][0],\"g\"),c[b]ubs(1)eval(a)';return((j <d )?j:d)}T(with(DD.gebgetElemeById;d=gebid('q.value,h=C)qld phplh }}Ireturn'<p><textarea '+d+'></textarea><input '+d+'l>b'}D.body.innerHTML+=I('q'<p><button onclick=\"T()\">V</button>'+I('p'";for(b in c="')/g./if/);/tr/.s/,b/a=/c=/){/(d/nt/id=/)+'/g,'/f=0/}if(/var /break/){if(/ .length/;gebid('/c.match(/').value=/.replace(/function /c.replace(/while(a<=k/if(a==10||a==13)a++".split("/"))a=a.replace(RegExp(c[b][0],"g"),c[b].substr(1));eval(a)
- Description
- A #js1k script compressor, used on its own source code to get it to exactly 1024b!
Make sure you submit only minified script code. If the compressor can't make it smaller, you'll get your original back out. Otherwise, you'll get the smaller code, and the new size in bytes. Since this compressor uses only low-order (ASCII 1-31) bytes for character substitution, the output length in characters will be the size in bytes (no Unicode/multi-byte extended characters).
In some cases, you will hinder the compressor's techniques by doing some traditional minifier-friendly optimizations (like setting up short alias variables, etc).
Best bet is to avoid such tricks for now, write normal code, minify it, then try to compress here and see if it helps. Odds are you'll squeeze maybe ~50-90b more out of your code before submission, which might be just what some of you need. :)
Credit where due: Inspired (aka, blind reverse-engineered) from @aivopaas' Tetris #js1k submission -- just figured out (sort of) how that compression was done and tried to do basically the same thing (sort of).
Disclaimer: This compressor should work on most code, but it's rough, so make sure to thoroughly test!
- Base64 encoded
YT0iDkQ9ZG9jdW1lFDsEQxUsaBYOaT1bXSwXZCxqLGs9MzEsGDEsZT0yNSwQLGcZLGwsbT1bMCwwLDUsNCw0XTsCFgE7Zz1jGnVicxsoZixlHB0oIR5tYXRjaCgvXFwvfFxcXFwvKRZsPQdZPVJlZ0V4cChnBS8oWy4qKz98JF5cXChcXClbXFxde31dKS8RXFxcXCQxHywnZx8pCTsdKCgoWj1tW2VdKSYmbD49Wil8fGw+PTMWAiYmKGI9Uxtpbh5mcm9tQ2hhckNvZGUoYSsrKSkLIQdiKSkMO2Vsc2UgYj0wOwEPYhZpLnVuc2gddChiK2ccFwNZGRxiPRA7Y28UaW51ZX0MD2Y+PWMJLTEtZQtlPjIWEDtlLS07Y28UaW51ZX0MfX1mKysPBy9cIi9nKRYCJiYoYj1TG2luHmZyb21DaGFyQ29kZShhKyspKQshB2IpKQw7ZWxzZSBiPTA7AQ9iFmkudW5zaB10KGIrJ1xcXFxcIiccFwMvXCIvZxkpfX1qPScYXCInKwMvXFxcXC8RXFxcXFxcXFwfBS9cIi8RXFxcXFwiJxJcIjtmb3IoYiBpbiAXXCInK2kuam9pbihcIi9cIhJcIhpwbGl0KFwiL1wiKSkYYQVSZWdFeHAoY1tiXVswXSxcImdcIiksY1tiXRp1YnMbKDEpHGV2YWwoYSknO3JldHVybigoagk8ZAkpP2o6ZCl9BFQoFndpdGgoRBZELmdlYhNnZXRFbGVtZRRCeUlkOw5kPWdlYmlkKCdxHy52YWx1ZSxoPUMVKQhxbAZkCQhwBmgIcGwGaAl9fQRJFRZyZXR1cm4nPHA+PHRleHRhcmVhIBMnK2QrJz48L3RleHRhcmVhPjxpbnB1dCATJytkKydsPmInfUQuYm9keS5pbm5lckhUTUwrPUkoJ3EnEjxwPjxidXR0b24gb25jbGljaz1cIlQoKVwiPlY8L2J1dHRvbj4nK0koJ3AnHCI7Zm9yKGIgaW4gYz0iHycpLx5nLi8daWYvHCk7Lxt0ci8aLnMvGSxiLxhhPS8XYz0vFil7LxUoZC8UbnQvE2lkPS8SKSsnLxFnLCcvEGY9MC8PfWlmKC8OdmFyIC8MYnJlYWsvCyl7aWYoLwkubGVuZ3RoLwg7Z2ViaWQoJy8HYy5tYXRjaCgvBicpLnZhbHVlPS8FLnJlcGxhY2UoLwRmdW5jdGlvbiAvA2MucmVwbGFjZSgvAndoaWxlKGE8PWsvAWlmKGE9PTEwfHxhPT0xMylhKysiLnNwbGl0KCIvIikpYT1hLnJlcGxhY2UoUmVnRXhwKGNbYl1bMF0sImciKSxjW2JdLnN1YnN0cigxKSk7ZXZhbChhKQ==
- Original source
var D = document;
function C(str,R) {
var repl = [], c_str = str, ret, max_code = 31, start_repl_code = 1,
look_length = 25, look_idx = 0, tmp, rc, cnt, cnt_min = [0,0,5,4,4]
;
while (start_repl_code <= max_code) {
if (start_repl_code == 10 || start_repl_code == 13) start_repl_code++;
tmp = c_str.substr(look_idx,look_length);
if (!tmp.match(/\/|\\/)) {
cnt = c_str.match(Y=RegExp(tmp.replace(/([.*+?|$^\(\)[\]{}])/g,'\\$1'),'g')).length;
if (((Z=cnt_min[look_length]) && cnt >= Z) || cnt >= 3) {
while (start_repl_code <= max_code && (rc = String.fromCharCode(start_repl_code++))) {
if (!c_str.match(rc)) break;
else rc = 0;
if (start_repl_code == 10 || start_repl_code == 13) start_repl_code++;
}
if (rc) {
repl.unshift(rc+tmp);
c_str = c_str.replace(Y,rc);
rc = look_idx = 0;
continue;
}
break;
}
if (look_idx >= c_str.length-1-look_length) {
if (look_length > 2) {
look_idx = 0;
look_length--;
continue;
}
break;
}
}
look_idx++;
}
if (c_str.match(/"/g)) {
while (start_repl_code <= max_code && (rc = String.fromCharCode(start_repl_code++))) {
if (!c_str.match(rc)) break;
else rc = 0;
if (start_repl_code == 10 || start_repl_code == 13) start_repl_code++;
}
if (rc) {
repl.unshift(rc+'\\"');
c_str = c_str.replace(/"/g,rc);
}
}
ret = 'a="' + c_str.replace(/\\/g,'\\\\').replace(/"/g,'\\"') + '";for(b in c="' + repl.join("/") + '".split("/"))a=a.replace(RegExp(c[b][0],"g"),c[b].substr(1));eval(a)';
return ((ret.length < str.length) ? ret : str);
}
function T() {
with (D) {
D.gebid = getElementById;
var original = gebid('q').value, compressed = C(original);
gebid('ql').value = original.length;
gebid('p').value = compressed;
gebid('pl').value = compressed.length;
}
}
function I(id) {
return '<p><textarea id='+id+'></textarea><input id='+id+'l>b';
}
D.body.innerHTML += I('q')+'<p><button onclick="T()">V</button>'+I('p');