什么用于压缩此代码?

时间:2013-04-05 12:17:13

标签: javascript

我正在尝试了解此代码中发生了什么:http://js1k.com/2013-spring/demo/1396

这看起来并不像我在Base62中被缩小或编码。当我在Vim中粘贴它时,到处都会出现奇怪的字符。有没有办法解码它?

2 个答案:

答案 0 :(得分:4)

这是使用数据URI方案

生成的

https://en.wikipedia.org/wiki/Data_URI_scheme

javascript文件作为包含文件内容的URI提供。许多代码都被URL转义,因此所有\都是。在此之前它可能已经缩小了。

这里的数据是一个完整的HTML文档。第一部分是HTML文件的开头:

javascript: '<!doctype html>\n<html>\n\t<head>\n\t\t<title>JS1k, 1k demo submission [1396]</title>\n\t\t<meta charset="utf-8" />\n\t</head>\n\t<body>\n\t\t<canvas id="c"></canvas>\n\t\t

之后是内联脚本:

var b = document.body;\n\t\t\tvar c = document.getElementsByTagName(\'canvas\')[0];\n\t\t\tvar a = c.getContext(\'2d\');\n\t\t\tdocument.body.clientWidth; // fix bug in webkit: http://qfox.nl/weblog/218\n\t\t

您可以轻松解码为:

var b = document.body;
var c = document.getElementsByTagName('canvas')[0];
var a = c.getContext('2d');
document.body.clientWidth; // fix bug in webkit: http://qfox.nl/weblog/218

等等。

答案 1 :(得分:2)

代码结束有脚本,用于解码代码

for (Y = 0; $ = 'zxqj`_^ZWVUQONMKJIHGCA@8$  ' [Y++];) 
     with(_.split($)) _ = join(pop());
eval(_)    

我把这个萤火虫......而不是eval(_)console.log( _ )

代码是

e = null;
T = function (b) {
    c.width = c.height = 19 * s;
    a.fillStyle = "#DB5";
    a.fillRect(0, 0, c.width, c.width);
    for (i = s / 2; i < c.width; i += s) a.moveTo(i, s / 2), a.lineTo(i, c.width - s / 2), a.moveTo(s / 2, i), a.lineTo(c.width - s / 2, i);
    a.stroke();
    b && (f = 19 * ~~(0.5 + (b.clientY - s / 2) / s) + ~~(0.5 + (b.clientX - s / 2) / s), t[f] == e && (t[f] = d, (L(f) | !(L(f + 1) & L(f - 1) & L(f + 19) & L(f - 19))) & (!m | f != n) ? "d" == b.type[5] ? (m = 0, u = f, d = !d, E(f + 1, d), E(f - 1, d), E(f + 19, d), E(f - 19, d), E(f)) : (t[f] = e, a.beginPath(), a.arc(~~(0.5 + (b.clientX - s / 2) / s) * s + s / 2, ~~ (0.5 + (b.clientY - s / 2) / s) * s + s / 2, s / 2 - 1, 0, 6.3, 1), a.strokeStyle = a.fillStyle = "rgba(0,0,0,0.3)", d && (a.fillStyle = "rgba(255,255,255,0.3)"), a.fill(), a.stroke()) : t[f] = e));
    a.strokeStyle = "#000";
    a.fillStyle = "#000";
    for (i = s / 2 + 75; i < c.width; i += 6 * s) for (h = s / 2 + 75; h < c.width; h += 6 * s) a.beginPath(), a.arc(i, h, 2, 0, 6.3, 1), a.fill();
    m && (t[n] = d, L(u) || (a.beginPath(), a.rect(n % 19 * s + s / 2 / 2, ~~ (n / 19) * s + s / 2 / 2, s / 2, s / 2), a.stroke()), t[n] = e);
    for (i = t.length; i--;) t[i] != e && (a.beginPath(), a.arc(i % 19 * s + s / 2, ~~ (i / 19) * s + s / 2, s / 2 - 1, 0, 6.3, 1), a.fillStyle = "#000", t[i] && (a.fillStyle = "#FFF"), a.fill(), a.stroke())
};
E = function (b, g) {
    if (!L(b, g)) {
        1 == w.length && (m = 1, n = b);
        for (i = w.length; i--;) t[w[i]] = e
    }
};
L = function (b, g) {
    w = [];
    g == e && (g = t[b]);
    l = function (b) {
        for (i = w.length; i--;) if (w[i] == b) return;
        w.push(b);
        0 != (b + 1) % 19 && t[b + 1] == g && l(b + 1);
        0 != b % 19 && t[b - 1] == g && l(b - 1);
        t[b + 19] == g && l(b + 19);
        t[b - 19] == g && l(b - 19)
    };
    if (g != e && g == t[b]) l(b);
    else return 1;
    for (i = w.length; i--;) if (0 != (w[i] + 1) % 19 && t[w[i] + 1] == e || 0 != w[i] % 19 && t[w[i] - 1] == e || 342 > w[i] && t[w[i] + 19] == e || 19 <= w[i] && t[w[i] - 19] == e) return 1;
    return 0
};
s = 25;
d = m = n = 0;
c.addEventListener("mousemove", T);
c.addEventListener("mousedown", T);
t = [];
T();
相关问题