UglifyJS实现浏览器端压缩混淆代码
大家知道UglifyJS,也知道在npm下进行压缩混淆js代码,那么在浏览器端是否可以直接压缩混淆代码呢,可以的,今天来演示一下在线调用UglifyJS
插件进行压缩混淆js代码。
示例如下,可在线直接运行
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>BFW NEW PAGE</title> <script id="bfwone" data="dep=jquery.17&err=0" type="text/javascript" src="http://repo.bfw.wiki/bfwrepo/js/bfwone.js"></script> <script type="text/javascript"> bready(function() { $("#codebtn").click(function(){ use(["uglify"], function() { var codes = $("#sourcecode").val(); var ast = UglifyJS.parse(codes); ast.figure_out_scope(); ast.compute_char_frequency(); ast.mangle_names(); $("#cofecode").val(ast.print_to_string()); //或者先压缩后混淆 var ast = UglifyJS.parse(codes); // compressor needs figure_out_scope too ast.figure_out_scope(); var compressor = UglifyJS.Compressor() ast = ast.transform(compressor); // need to figure out scope again so mangler works optimally ast.figure_out_scope(); ast.compute_char_frequency(); ast.mangle_names(); // get Ugly code back :) //ast.print_to_string(); $("#cofecode2").val(ast.print_to_string()); }); }); }); </script> <style> textarea { height: 300px; width: 100%; } </style> </head> <body> <textarea id="sourcecode" placeholder="源代码"> function add(first, second) { return first + second; } </textarea> <input type="button" id="codebtn" value="压缩混淆" /> <textarea id="cofecode" placeholder="混淆后代码"></textarea> <textarea id="cofecode2" placeholder="先压缩后混淆代码"></textarea> </body> </html>
网友评论0