Last active
July 31, 2024 23:58
-
-
Save PixelMelt/175ad2e5fc800dd2cd03a8c2d2a835ab to your computer and use it in GitHub Desktop.
Dwitter.net JS Compressors
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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