2009-05-15 23:46:54 +00:00
< !DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<!--
(c) 2006-2009: Einar Lielmanis, einars@gmail.com
-->
< html xmlns = "http://www.w3.org/1999/xhtml" xml:lang = "en" lang = "en" >
< head >
< meta http-equiv = "Content-Type" content = "text/html; charset=utf-8" / >
< title > Online javascript beautifier< / title >
< script type = "text/javascript" >
function add_onload_function(fn)
{
var oe=window.onload;
window.onload = function() { if (oe) oe(); fn(); }
}
add_onload_function(function() {
2009-08-18 01:07:18 +00:00
var tabsize = get_var('tabsize');
if (tabsize) {
document.getElementById('tabsize').value = tabsize;
}
2009-05-15 23:46:54 +00:00
var c = document.forms[0].content;
c & & c.setSelectionRange & & c.setSelectionRange(0, 0);
c & & c.focus & & c.focus();
});
function starts_with(str, what)
{
return str.substr(0, what.length) === what;
}
function trim_leading_comments(str)
{
// very basic. doesn't support /* ... */
str = str.replace(/^(\s*\/\/[^\n]*\n)+/, '');
str = str.replace(/^\s+/, '');
return str;
}
function unpacker_filter(source)
{
if (document.getElementById('detect-packers').checked) {
2009-10-22 06:18:14 +00:00
var stripped_source = trim_leading_comments(source);
//try {
if (starts_with(stripped_source.toLowerCase().replace(/ +/g, ''), 'eval(function(p,a,c,k')) {
eval('var unpacked_source = ' + stripped_source.substring(4) + ';')
return unpacker_filter(unpacked_source);
} else if (JavascriptObfuscator.detect(stripped_source)) {
var unpacked = JavascriptObfuscator.unpack(stripped_source);
if (unpacked !== stripped_source) { // avoid infinite loop if nothing done
return unpacker_filter(unpacked);
}
2009-05-15 23:46:54 +00:00
}
2009-10-22 06:18:14 +00:00
//} catch (error) {
//source = '// jsbeautifier: unpacking failed\n'
//+ '// You may wish to send me a report to einar@jsbeautifier.org\n'
//+ source;
//}
2009-05-15 23:46:54 +00:00
}
return source;
}
function do_js_beautify()
{
document.getElementById('beautify').disabled = true;
var js_source = document.getElementById('content').value.replace(/^\s+/, '');
var indent_size = document.getElementById('tabsize').value;
var indent_char = ' ';
var preserve_newlines = document.getElementById('preserve-newlines').checked;
if (indent_size == 1) {
indent_char = '\t';
}
if (js_source & & js_source[0] === '< ' & & js_source.substring(0, 4) !== '<!-- ') {
document.getElementById('content').value = style_html(js_source, indent_size, indent_char, 80);
} else {
document.getElementById('content').value =
2009-08-07 19:32:42 +00:00
js_beautify(unpacker_filter(js_source), {indent_size: indent_size, indent_char: indent_char, preserve_newlines:preserve_newlines, space_after_anon_function:true});
2009-05-15 23:46:54 +00:00
}
document.getElementById('beautify').disabled = false;
return false;
}
2009-08-18 01:07:18 +00:00
function get_var( name )
{
var res = new RegExp( "[\\?& ]" + name + "=([^& #]*)" ).exec( window.location.href );
return res ? res[1] : "";
}
2009-10-22 06:18:14 +00:00
function run_tests()
{
var st = new SanityTest();
run_beautifier_tests(st);
JavascriptObfuscator.run_tests(st);
return st.results();
}
2009-05-15 23:46:54 +00:00
< / script >
2009-10-22 06:18:14 +00:00
< script type = "text/javascript" src = "sanitytest.js" > < / script >
2009-05-15 23:46:54 +00:00
< script type = "text/javascript" src = "beautify.js" > < / script >
< script type = "text/javascript" src = "beautify-tests.js" > < / script >
2009-10-22 06:18:14 +00:00
< script type = "text/javascript" src = "javascriptobfuscator_unpacker.js" > < / script >
2009-05-15 23:46:54 +00:00
< script type = "text/javascript" src = "HTML-Beautify.js" > < / script >
< style type = "text/css" >
/* I guess I need a CSS beautifer as well */
form {
margin: 0 10px 0 10px;
}
textarea {
width: 100%;
2009-10-22 06:18:14 +00:00
height: 420px;
2009-05-15 23:46:54 +00:00
border: 1px solid #ccc; padding: 3px;
}
h1 {
font-family: "trebuchet ms", arial, sans-serif;
font-weight: normal;
font-size: 28px;
color: #666;
margin-bottom: 15px;
border-bottom: 1px solid #666;
}
a {
color: #36d;
}
select {
width: 19%;
}
button {
width: 40%;
cursor: pointer;
}
body, label, button, select {
font-family: "myriad web", verdana, arial, helvetica, sans-serif;
font-size: 14px;
}
textarea, pre, span.code {
font-family: terminus, consolas, "lucida console", "courier new", courier, monospace;
font-size: 12px;
}
div#bottom {
color: #333;
margin: 20px;
}
a#signature {
background: url(http://spicausis.lv/spic-sign-blog.png) no-repeat bottom right;
display:block;
width: 15px;
height: 21px;
position: fixed;
bottom: 0px;
right: 0px;
}
h2 {
color: #555;
font-size: 14px;
2009-11-27 02:55:09 +00:00
margin: 18px 0 4px 0;
2009-05-15 23:46:54 +00:00
}
p {
line-height: 150%;
font-size: 14px;
margin: 0;
}
div#footer {
margin: 20px 0 0 0;
font-size: 12px;
border-top: 1px solid #ddd;
padding-top: 16px;
2009-11-27 02:55:09 +00:00
}
label {
cursor: pointer;
2009-05-15 23:46:54 +00:00
}
< / style >
< / head >
< body >
2009-11-17 08:41:44 +00:00
< h1 > Javascript unpacker and beautifier< / h1 >
2009-05-15 23:46:54 +00:00
< form method = "post" action = "?" >
< textarea rows = "30" cols = "30" name = "content" id = "content" >
/* paste in your code and press Beautify button */
if('this_is'==/an_example/){do_something();}else{var a=b?(c%d):e[f];}
< / textarea > < br / >
< button onclick = "return do_js_beautify()" id = "beautify" > Beautify< / button >
< select name = "tabsize" id = "tabsize" >
< option value = "1" > indent with a tab character< / option >
< option value = "2" > indent with 2 spaces< / option >
< option value = "3" > indent with 3 spaces< / option >
< option value = "4" selected = "selected" > indent with 4 spaces< / option >
< option value = "8" > indent with 8 spaces< / option >
< / select >
2009-08-13 13:06:54 +00:00
< input type = "checkbox" id = "preserve-newlines" checked = "checked" / > < label for = "preserve-newlines" > Preserve empty lines?< / label >
2009-05-15 23:46:54 +00:00
< input type = "checkbox" id = "detect-packers" checked = "checked" / > < label for = "detect-packers" > Detect packers?< / label >
< / form >
< div id = "bottom" >
2009-11-17 08:41:44 +00:00
< p > This little beautifier will reformat and reindent any ugly javascript, unpack scripts packed by
the popular < a href = "http://dean.edwards.name/packer/" > Dean Edward's packer,< / a > as well as deobfuscate scripts
processed by javascriptobfuscator.com.< / p >
< p > The source code for the latest version is always available on < a
2009-05-15 23:46:54 +00:00
href="http://github.com/einars/js-beautify">github< / a > , and you can download the beautifier for
local use (< a href = "http://github.com/einars/js-beautify/zipball/master" > zip< / a > , < a href = "http://github.com/einars/js-beautify/tarball/master" > tar.gz< / a > ) as well.< / p >
< h2 > Formatting from command-line< / h2 >
2009-10-20 12:08:34 +00:00
< p > To beautify from the command-line you can use provided beautify-cl.js script, using < a href = "http://www.mozilla.org/rhino/" > Rhino javascript engine< / a > . See the file contents for the details.< / p >
2009-05-15 23:46:54 +00:00
< h2 > < a href = "http://fiddler2.com/" > Fiddler< / a > < / h2 >
2009-08-24 09:19:56 +00:00
< p > This popular web debugging proxy for Windows has a < a href = "http://fiddler2.com/Fiddler2/extensions.asp" > Javascript Formatter addon< / a > (based on this beautifier) which can reformat javascript on the fly.< / p >
< h2 > Vim< / h2 >
< p > Aj3423 converted the script to vimscript — and so now there is a < a href = "http://www.vim.org/scripts/script.php?script_id=2727" > vim plugin< / a > for the quality javascript beautifying.< / p >
2009-05-15 23:46:54 +00:00
< h2 > Other nice things< / h2 >
2009-09-03 03:08:51 +00:00
< p > If you're writing javascript code, < a href = "http://jslint.com/" > JSLint< / a > is a really fine piece of software, too. You don't have to follow its recommendations blindly, but understanding what it says about your code can greatly improve your skills.< / p >
2009-05-15 23:46:54 +00:00
< h2 > Contacts< / h2 >
2009-10-22 06:18:14 +00:00
< p > If you find some problems with the generated javascript, adapt the script for your favorite editor, or something, my email is einar@jsbeautifier.org.< / p >
2009-05-15 23:46:54 +00:00
< div id = "footer" >
2009-11-27 02:55:09 +00:00
< a href = "#" style = "border-bottom: 1px dashed #36d; text-decoration: none;" onclick = "document.getElementById('testresults').style.display='block'; document.getElementById('testresults').innerHTML=run_tests(); return false;" > Run the tests< / a >
< br / >
2009-05-15 23:46:54 +00:00
< pre id = "testresults" > < / pre >
2009-11-27 02:55:09 +00:00
Written by < a href = "mailto:einar@jsbeautifier.org" > Einar Lielmanis< / a > , with the help of < a href = "http://jason.diamond.name/weblog/" > Jason Diamond< / a > , Patrick Hof, Nochum, Andreas Schneider, Dave Vasilevsky, < a href = "http://my.opera.com/Vital/blog/" > Vital,< / a > Ron Baldwin, Gabriel Harrison and others.
2009-05-15 23:46:54 +00:00
< / div >
< / div >
< a id = "signature" href = "http://spicausis.lv/" > < / a >
< script src = "http://www.google-analytics.com/ga.js" type = "text/javascript" > < / script >
< script type = "text/javascript" >
if (window._gat) {
var tracker = _gat._getTracker("UA-7409939-1");
if (tracker & & tracker._trackPageview) {
tracker._trackPageview();
}
}
< / script >
< / body >
< / html >