Can compressed javascript be uncompressed

2019-02-12 17:54发布

Is it possible to uncompress (if that's the right term even) for code like below?

var vote=function(){var k={informModerator:-1,undoMod:0,acceptedByOwner:1,upMod:2,downMod:3,offensive:4,favorite:5,close:6,reopen:7,deletion:10,undeletion:11,spam:12};var f=imagePath+"vote-arrow-down.png";var c=imagePath+"vote-arrow-down-on.png";var x=imagePath+"vote-arrow-up.png";var w=imagePath+"vote-arrow-up-on.png";var A=imagePath+"vote-favorite-on.png";var o=imagePath+"vote-favorite-off.png";var l=function(){var C='<a href="/users/login?returnurl='+escape(document.location)+'">login or register</a>';$("div.vote").find("img").not(".vote-accepted").unbind("click").click(function(D){u($(D.target),"Please "+C+" to use voting.")});z().unbind("click").click(function(D){u($(D.target),"Please "+C+" to flag this post.")})};var B=function(C){if(!C){C="div.vote"}$(C).find("img.vote-

I did search stackoverflow for this question and found no results

5条回答
Emotional °昔
2楼-- · 2019-02-12 18:19

In your specific example, you should be able to uncompress it.

Note, however, that most compressors will rename variables. At that point, the code is, IMO, no longer human readable.

var vote = function() {
    var k = {
        informModerator: -1,
        undoMod: 0,
        acceptedByOwner: 1,
        upMod: 2,
        downMod: 3,
        offensive: 4,
        favorite: 5,
        close: 6,
        reopen: 7,
        deletion: 10,
        undeletion: 11,
        spam: 12
    };
    var f = imagePath + "vote-arrow-down.png";
    var c = imagePath + "vote-arrow-down-on.png";
    var x = imagePath + "vote-arrow-up.png";
    var w = imagePath + "vote-arrow-up-on.png";
    var A = imagePath + "vote-favorite-on.png";
    var o = imagePath + "vote-favorite-off.png";
    var l = function() {
        var C = '<a href="/users/login?returnurl=' + escape(document.location) + '">login or register</a>';
        $("div.vote").find("img").not(".vote-accepted").unbind("click").click(function(D) {
            u($(D.target), "Please " + C + " to use voting.")
        });
        z().unbind("click").click(function(D) {
            u($(D.target), "Please " + C + " to flag this post.")
        })
    };
    var B = function(C) {
        if (!C) {
            C = "div.vote"
        }
        $(C).find("img.vote-")
    };
查看更多
狗以群分
3楼-- · 2019-02-12 18:22

There is a feature called "Pretty Print" at Source tab in Developer Tools of Google Chrome. Click on curly bracket icon and see the formatted code.

Here is a screen shot

查看更多
劳资没心,怎么记你
4楼-- · 2019-02-12 18:27

If what you are trying to do is see the original variables used to describe the code, then no. You can always take the time to run it through a formatter to make it easier to read visually but the variable and function names are lost forever.

查看更多
姐就是有狂的资本
5楼-- · 2019-02-12 18:35

I think something like Eclipse can auto-format it for you. Won't be able to get back any of the original variable names though.

查看更多
乱世女痞
6楼-- · 2019-02-12 18:40

Yes. Copy / paste here: http://jsbeautifier.org/

That will only reformat the layout. You cannot restore variable/function names.

Related on MetaSO: Can we get an un-obfuscated version of the vote object?

查看更多
登录 后发表回答