This file contains 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
JAVASCRIPT GOLFING TOOL DEMO - www.scriptcompress.com/golf.htm | |
One technique I use often is taking something like x=x.split(" ").join("");y=y.split(" ").join(""); that I may use often in a script and make it a bit smaller (or part of obfuscating) throughout the script. I will set it up like x=x[S='split'](" ")[J='join']("");y=y[S](" ")[J](""); | |
Take a script like: | |
var roll={d4:function(){return Math.floor(4*Math.random())+1},d6:function(){return Math.floor(6*Math.random())+1},d8:function(){return Math.floor(8*Math.random())+1},d10:function(){return Math.floor(10*Math.random())+1},d12:function(){return Math.floor(12*Math.random())+1},d20:function(){return Math.floor(20*Math.random())+1}};alert("rolling D4 : "+roll.d4());alert("rolling D20 : "+roll.d20()); | |
Can be rewritten as: |
This file contains 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 replacer(s, f, r) { | |
//s=string | |
//f=find | |
//r=replace | |
return s.split(RegExp(eval(f))).join(r); | |
} | |
alert(replacer("480Vi76s76i5t7 7w5876w87w58.5W76H2A56K.2134c54o67m0", "/[0-9]/g", "")); |
This file contains 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 characterWays(a) { | |
var decimal = a.charCodeAt(0); | |
var octal = decimal.toString(8); | |
var hex = decimal.toString(16); | |
var oct = "\\" + octal; | |
var hexValue = "0x" + hex; | |
var uniValue = "U+" + hex; | |
var escUni = "" + hex; | |
var escURL = "%" + hex; | |
var escHex = "\\x" + hex; |
This file contains 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 allAnagrams(r) { | |
var n, a, t, l, e, s; | |
if (r.length < 2) { | |
return [ r ]; | |
} | |
for (n = [], a = 0; a < r.length; a++) { | |
for (t = r[a], l = r.substr(0, a) + r.substr(a + 1, r.length - 1), e = allAnagrams(l), | |
s = 0; s < e.length; s++) { | |
n.push(t + e[s]); | |
} |
This file contains 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 fullEscape(r){ | |
return r.replace(/./g, function(e){ | |
return "%"+e.charCodeAt(0).toString(16); | |
}); | |
}; | |
alert(fullEscape("JavaScript Packer")); |
This file contains 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 escapeHTML(Δ){ | |
return Δ.replace(/./g, function(e){ | |
return "&#"+e.charCodeAt(0)+";"; | |
}); | |
}; | |
alert(escapeHTML("JavaScript Packer")); |
This file contains 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 octal(П){ | |
return П.replace(/./g, function(e){ | |
return "\\"+e.charCodeAt(0).toString(8); | |
}); | |
}; | |
alert(octal("JavaScript Packer")); | |
//extreme JavaScript escaping |
This file contains 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 hex(Δ){ | |
return Δ.replace(/./g, function(e){ | |
return "\\x"+e.charCodeAt(0).toString(16); | |
}); | |
}; | |
alert(hex("JavaScript Packer")); | |
//extreme JavaScript escaping |
This file contains 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 codepoints(Δ) { | |
return Δ.replace(/./g, function(Δ) { | |
return Δ.charCodeAt(0) + " "; | |
}).trim().replace(/ /g, ","); | |
} | |
alert(codepoints("JavaScript Packer")); |
This file contains 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
//212 bytes | |
function codepoints(ΔstringΔ) { | |
return ΔstringΔ.replace(/./g, function(ΔstringΔ) { | |
return ΔstringΔ.charCodeAt(0) + " "; | |
}).trim().replace(/ /g, ","); | |
} | |
alert(codepoints("JavaScript Packer")); | |
//first lets get rid of uneeded whitespace and linebreaks |
OlderNewer