Skip to content

Instantly share code, notes, and snippets.

@PixelMelt
Last active July 31, 2024 23:58
Show Gist options
  • Save PixelMelt/175ad2e5fc800dd2cd03a8c2d2a835ab to your computer and use it in GitHub Desktop.
Save PixelMelt/175ad2e5fc800dd2cd03a8c2d2a835ab to your computer and use it in GitHub Desktop.
Dwitter.net JS Compressors
function golfPack(code){
function chinaPacker(code) {
const unicodeChars = [];
for (let i = 0; i < code.length; i += 2) {
const char1 = code[i];
const char2 = code[i + 1] || ' ';
const codePoint = (char1.charCodeAt(0) << 8) | char2.charCodeAt(0);
const unicodeChar = String.fromCodePoint(codePoint);
unicodeChars.push(unicodeChar);
}
const compressedCode = unicodeChars.join('');
return `eval(unescape(escape\`${compressedCode}\`.replace(/u(..)/g,"$1%")))`;
}
function blockPacker(code) {
const charCodes = [];
for (let i = 0; i < code.length; i++) {
const charCode = code.charCodeAt(i);
charCodes.push(charCode);
}
const packedString = charCodes.map((charCode, index) => {
return String.fromCharCode(0xF000 + charCode);
}).join('');
return `eval(unescape(escape\`${packedString}\`.replace(/u../g, '')))`;
}
let block = blockPacker(code)
let china = chinaPacker(code)
console.log("block: " + block.length, block)
console.log("china: " + china.length, china)
if(china.length >= block.length){
return block
}
return china
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment