A few months ago I wrote a simple Javascript beautifier, which suited my needs at the time. But since then while dissecting longer AJAX-centric scripts in various websites, I found some things that were giving the beautifier some trouble. So I took some time this morning to fix a few bugs and improve overall performance.
Some of you may be asking, “What is a beautifier?” Put in nasty obfuscated code that is all run together, and it spits out something that's nicely formatted and very readable:
|
function layoutmouseup() {if ((moving != 0) && (target != 0)) {rearrange( moving, movingcol, target, targetcol);var targ = target;if (movingcol == targetcol && target > moving) {targ = targ - 1;}displaylayout();}moving = 0;movingcol = 0;target = 0;targetcol = 0;} |
 |
function layoutmouseup()
{
if ((moving != 0) && (target != 0))
{
rearrange(moving, movingcol...
var targ = target;
if (movingcol == targetcol ...
{
targ = targ - 1;
}
displaylayout();
} moving = 0;
movingcol = 0;
target = 0;
targetcol = 0;
} |
I've now tested it with all kinds of crazy obfuscated Javascript, and the only thing it doesn't handle properly at this point is RegEx. I'll have to save that update for the next revision. For the moment it's a pretty good way to quickly get a handle on obfuscated code. Pull some crazy code out from any compacted .js file out there and give it a try:
http://hdvforever.com/beautify.aspx
This will always remain 100% free and open-source. I hope the developer community at large can benefit from it.
(My post about the original version is here. The links there point to the updated code.)