还原压缩过的JS代码

有时不免会碰到的JavaScript代码被压缩为.min.js格式,难以阅读,比如:
在这里插入图片描述
其实想要还原这种代码很简单,只需要用谷歌浏览器,或者使用谷歌内核的浏览器,就可以将代码还原出来。

1.将代码在谷歌浏览器上运行起来
2.按F12键打开开发工具,点击Sources一栏
3.找到要还原的JS文件
4.点击开发工具最下边的{}就可以完成还原
5.还原后需要将代码复制出去,然后新建一个JS文件粘贴进去保存。浏览器不会改变原文件的格式。

在这里插入图片描述

  • 9
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
由Douglas Crockford创建的JSMin是一个筛选程序,用于JavaScript文件中删除注释和不必要的空格。这个程序通常能够使文件大小减半,从而节省下载时间。 压缩包里包含了用C写的源码,及可执行程序 由于看到三条评论说没有用,在里我必须说明一下,下面那三个白痴肯定没学过c语言,更没用过c编译好的.exe文件。 以下是c里的源码大家可以先看觉得可用再下 #include <stdlib.h> #include <stdio.h> static int theA; static int theB; static int theLookahead = EOF; /* isAlphanum -- return true if the character is a letter, digit, underscore, dollar sign, or non-ASCII character. */ static int isAlphanum(int c) { return ((c >= 'a' && c <= 'z') || (c >= '0' && c <= '9') || (c >= 'A' && c <= 'Z') || c == '_' || c == '$' || c == '\\' || c > 126); } /* get -- return the next character from stdin. Watch out for lookahead. If the character is a control character, translate it to a space or linefeed. */ static int get() { int c = theLookahead; theLookahead = EOF; if (c == EOF) { c = getc(stdin); } if (c >= ' ' || c == '\n' || c == EOF) { return c; } if (c == '\r') { return '\n'; } return ' '; } /* peek -- get the next character without getting it. */ static int peek() { theLookahead = get(); return theLookahead; } /* next -- get the next character, excluding comments. peek() is used to see if a '/' is followed by a '/' or '*'. */ static int next() { int c = get(); if (c == '/') { switch (peek()) { case '/': for (;;) { c = get(); if (c <= '\n') { return c; } } case '*': get(); for (;;) { switch (get()) { case '*': if (peek() == '/') { get(); return ' '; } break; case EOF: fprintf(stderr, "Error: JSMIN Unterminated comment.\n"); exit(1); } } default: return c; } } return c; } /* action -- do something! What you do is determined by the argument: 1 Output A. Copy B to A. Get the next B. 2 Copy B to A. Get the next B. (Delete A). 3 Get the next B. (Delete B). action treats a string as a single character. Wow! action recognizes a regular expression if it is preceded by ( or , or =. */ static void action(int d) { switch (d) { case 1: putc(theA, stdout); case 2: theA = theB; if (theA == '\'' || theA == '"') { for (;;) { putc(theA, stdout); theA = get(); if (theA == theB) { break; } if (theA == '\\') { putc(theA, stdout); theA = get(); } if (theA == EOF) { fprintf(stderr, "Error: JSMIN unterminated string literal."); exit(1); } } } case 3: theB = next(); if (theB == '/' && (theA == '(' || theA == ',' || theA == '=' || theA == ':' || theA == '[' || theA == '!' || theA == '&' || theA == '|' || theA == '?' || theA == '{' || theA == '}' || theA == ';' || theA == '\n')) { putc(theA, stdout); putc(theB, stdout); for (;;) { theA = get(); if (theA == '[') { for (;;) { putc(theA, stdout); theA = get(); if (theA == ']') { break; } if (theA == '\\') { putc(theA, stdout); theA = get(); } if (theA == EOF) { fprintf(stderr, "Error: JSMIN unterminated set in Regular Expression literal.\n"); exit(1); } } } else if (theA == '/') { break; } else if (theA =='\\') { putc(theA, stdout); theA = get(); } if (theA == EOF) { fprintf(stderr, "Error: JSMIN unterminated Regular Expression literal.\n"); exit(1); } putc(theA, stdout); } theB = next(); } } } /* jsmin -- Copy the input to the output, deleting the characters which are insignificant to JavaScript. Comments will be removed. Tabs will be replaced with spaces. Carriage returns will be replaced with linefeeds. Most spaces and linefeeds will be removed. */ static void jsmin() { theA = '\n'; action(3); while (theA != EOF) { switch (theA) { case ' ': if (isAlphanum(theB)) { action(1); } else { action(2); } break; case '\n': switch (theB) { case '{': case '[': case '(': case '+': case '-': action(1); break; case ' ': action(3); break; default: if (isAlphanum(theB)) { action(1); } else { action(2); } } break; default: switch (theB) { case ' ': if (isAlphanum(theA)) { action(1); break; } action(3); break; case '\n': switch (theA) { case '}': case ']': case ')': case '+': case '-': case '"': case '\'': action(1); break; default: if (isAlphanum(theA)) { action(1); } else { action(3); } } break; default: action(1); break; } } } } /* main -- Output any command line arguments as comments and then minify the input. */ extern int main(int argc, char* argv[]) { int i; for (i = 1; i < argc; i += 1) { fprintf(stdout, "// %s\n", argv[i]); } jsmin(); return 0; }
### 回答1: 反压缩是指将经过压缩JavaScript代码重新转换为可读性更强、更易理解的格式。在开发中,有时候为了减小文件大小或者加密保护代码,我们会对JavaScript代码进行压缩操作。但是,压缩后的代码对于开发者来说很难看懂,不利于维护和调试。 为了解决这个问题,我们可以通过使用反压缩工具将压缩过的JavaScript代码转换为更易读懂的格式。常见的反压缩工具包括UglifyJS、Closure Compiler等。 使用这些工具,你可以将压缩代码中的变量和函数名还原为原始的命名方式,去除代码中的无用字符和空格,并格式化代码的缩进、换行等,使其更易阅读和理解。 反压缩后的JavaScript代码不仅便于开发者进行代码审查和调试,也能更好地组织和维护代码。此外,反压缩工具还能检测并修复代码中的一些潜在问题,提高代码质量和性能。 需要注意的是,虽然反压缩工具可以将代码转换为易读的格式,但是变量和函数名的含义可能仍然无法推测,因此在进行反压缩后,还需要仔细阅读代码并理解其中逻辑和用途。 总之,通过使用反压缩工具,我们可以将压缩JavaScript代码还原为易读的格式,提高代码的可维护性和可理解性,方便开发者进行代码审查和调试,以及对代码进行进一步的修改和优化。 ### 回答2: 在JavaScript中,实现反压缩的方法有多种。一种常见的方法是使用压缩库或插件来进行反压缩。 常见的压缩库有Brotli、Gzip和Deflate等。这些库可以将JavaScript代码进行压缩,以减小文件大小,并提高加载速度。要反压缩这些压缩后的代码,我们需要使用相应的函数或方法。 例如,对于Brotli压缩,可以使用Brotli库中的函数来进行反压缩。首先,我们需要通过下载并引入Brotli库的脚本文件来使用它。然后,我们可以使用Brotli库提供的解压函数将压缩JavaScript代码压缩回原始状态。这样,我们就可以获取到原始的未压缩JavaScript代码。 类似地,对于Gzip和Deflate压缩,也有相应的库和方法可以进行反压缩。通过引入相应的库,并使用其提供的解压函数,我们可以将压缩JavaScript代码压缩回原始状态。 总之,要实现JavaScript的反压缩,我们需要使用相应的压缩库或插件,并调用其提供的解压函数或方法来反压缩代码。这样,我们就能够获取到原始的未压缩JavaScript代码,并进行后续的操作。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值