forked from beautifier/js-beautify
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
330 lines (301 loc) · 11.5 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<!--
(c) 2006-2010: Einar Lielmanis, einars@jsbeautifier.org
-->
<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() {
var tabsize = get_var('tabsize');
var braces_on_own_line = get_var('braces');
var c;
if (tabsize) {
document.getElementById('tabsize').value = tabsize;
}
if (braces_on_own_line) {
document.getElementById('braces-on-own-line').checked = 'checked';
}
if (get_var('test')) {
run_tests();
} else {
c = document.forms[0].content;
c && c.setSelectionRange && c.setSelectionRange(0, 0);
c && c.focus && c.focus();
}
});
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) {
var stripped_source = trim_leading_comments(source);
var unpacked = '';
if (P_A_C_K_E_R.detect(stripped_source)) {
unpacked = P_A_C_K_E_R.unpack(stripped_source);
if (unpacked !== stripped_source) {
return unpacker_filter(unpacked);
}
}
if (EscapedBookmarklet.detect(source)) {
unpacked = EscapedBookmarklet.unpack(source);
if (unpacked !== stripped_source) {
return unpacker_filter(unpacked);
}
}
if (JavascriptObfuscator.detect(stripped_source)) {
unpacked = JavascriptObfuscator.unpack(stripped_source);
if (unpacked !== stripped_source) {
return unpacker_filter(unpacked);
}
}
}
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;
var keep_array_indentation = document.getElementById('keep-array-indentation').checked;
var braces_on_own_line = document.getElementById('braces-on-own-line').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 =
js_beautify(unpacker_filter(js_source), {
indent_size: indent_size,
indent_char: indent_char,
preserve_newlines:preserve_newlines,
braces_on_own_line: braces_on_own_line,
keep_array_indentation:keep_array_indentation,
space_after_anon_function:true});
}
document.getElementById('beautify').disabled = false;
return false;
}
function get_var( name )
{
var res = new RegExp( "[\\?&]" + name + "=([^&#]*)" ).exec( window.location.href );
return res ? res[1] : "";
}
function run_tests()
{
var st = new SanityTest();
run_beautifier_tests(st);
JavascriptObfuscator.run_tests(st);
P_A_C_K_E_R.run_tests(st);
EscapedBookmarklet.run_tests(st);
document.getElementById('testresults').style.display='block';
document.getElementById('testresults').innerHTML=st.results();
}
</script>
<script type="text/javascript" src="beautify.js" ></script>
<script type="text/javascript" src="beautify-html.js" ></script>
<script type="text/javascript" src="tests/sanitytest.js" ></script>
<script type="text/javascript" src="tests/beautify-tests.js" ></script>
<script type="text/javascript" src="unpackers/javascriptobfuscator_unpacker.js" ></script>
<script type="text/javascript" src="unpackers/bookmarklet_unpacker.js" ></script>
<script type="text/javascript" src="unpackers/p_a_c_k_e_r_unpacker.js" ></script>
<style type="text/css">
/* I guess I need a CSS beautifer as well */
* {
margin: 0;
padding: 0;
}
div#wrap {
padding: 0 15px;
}
form {
margin: 0 0 20px 0;
}
textarea {
width: 100%;
height: 420px;
border: 0;
}
h1 {
font-family: "trebuchet ms", arial, sans-serif;
font-weight: normal;
font-size: 28px;
color: #666;
margin: 10px 10px 15px 10px;
border-bottom: 1px solid #666;
}
a {
color: #36d;
}
select {
width: 190px;
}
button {
width: 100%;
padding: 3px 5px;
cursor: pointer;
bordeR: 1px solid #ccc;
border-bottom: 1px solid #999;
border-right: 1px solid #999;
margin-top: 2px;
background-color: #eee;
}
body {
font: 14px "myriad web", verdana, arial, helvetica, sans-serif;
}
body, label, button, select {
font-family: "myriad web", verdana, arial, helvetica, sans-serif;
}
textarea, pre, span.code {
font-family: consolas, Terminus, "lucida console", "courier new", courier, monospace;
}
div#bottom {
color: #333;
}
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;
margin: 18px 0 4px 0;
font-size: 14px;
}
p {
line-height: 150%;
}
div#footer {
margin: 20px 0 0 0;
font-size: 12px;
border-top: 1px solid #ddd;
padding-top: 16px;
}
label {
cursor: pointer;
}
fieldset {
border: 0;
padding: 0;
}
fieldset#textarea div {
border: 1px solid #ccc;
padding: 3px;
}
fieldset#options {
width: 200px;
margin-left: 10px;
float: right;
}
fieldset#options h2 {
margin-top: 0;
}
fieldset ul {
list-style: none;
}
fieldset li {
margin-bottom: 6px;
}
fieldset#textarea {
text-align: right;
}
pre {
margin: 10px 0;
}
</style>
</head>
<body>
<div id="wrap">
<h1>Javascript unpacker and beautifier</h1>
<form method="post" action="?">
<fieldset id="options">
<h2>Options</h2>
<ul>
<li><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></li>
<li><input type="checkbox" id="braces-on-own-line" /><label for="braces-on-own-line"> Braces on own line</label><br /></li>
<li><input type="checkbox" id="preserve-newlines" checked="checked" /><label for="preserve-newlines"> Preserve empty lines?</label><br /></li>
<li><input type="checkbox" id="detect-packers" checked="checked" /><label for="detect-packers"> Detect packers?</label><br /></li>
<li><input type="checkbox" id="keep-array-indentation" /><label for="keep-array-indentation"> Keep array indentation?</label></li>
</ul>
</fieldset>
<fieldset id="textarea">
<div><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></div>
<button onclick="return do_js_beautify()" id="beautify">Beautify</button>
</fieldset>
</form>
<div id="bottom">
<p>This little beautifier will reformat and reindent bookmarklets, 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
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>
<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>
<h2><a href="http://fiddler2.com/">Fiddler</a></h2>
<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>
<h2>gEdit</h2>
<p>Fabio Nagao has written some <a href="http://github.com/nagaozen/gedit-tunnings/">tips for the gEdit users,</a> among them he tells how to integrate the beautifier into the editor.</p>
<h2>Other nice things</h2>
<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>
<h2>Support</h2>
<p>Some of you have expressed an esoteric wish to thank me for the beautifier financially, and I gladly agree to that.</p>
<p>As the beautifier is — and always will be — completely free and open, donating is a wonderful thing to do and it will probably make you feel good and warm inside.
<form style="margin-top: 5px" action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_s-xclick">
<input type="hidden" name="hosted_button_id" value="TL28UJK2ARCUJ">
<input type="image" src="http://spicausis.lv/misc/paypal-donate.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!">
<img alt="" border="0" src="https://www.paypal.com/en_US/i/scr/pixel.gif" width="1" height="1">
</form>
<h2>Contacts</h2>
<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>
<div id="footer">
<a href="#" style="border-bottom: 1px dashed #36d; text-decoration: none;" onclick="run_tests(); return false;">Run the tests</a>
<br />
<pre id="testresults"></pre>
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 Sossonko, Andreas Schneider, Dave Vasilevsky, <a href="http://my.opera.com/Vital/blog/">Vital Batmanov,</a> Ron Baldwin, Gabriel Harrison and others.
</div>
</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>