Monday, December 5, 2016

Baidu Fanyi

var url = "http://fanyi.baidu.com/v2transapi";
var form = {
                    from: "en",
                    to: "zh",
                    query: "hot",
                    transtype: "realtime",
                    simple_means_flag: 3 };
$.post(url, form, showMsg);
------------------------------------------------------------
"liju_result" decoding codes are in the  "index_60f64ad.js" file
.....................................................................
var u = ["《柯林斯高阶英汉双解学习词典》", "《汉英大词典》", "百度翻译例句库"];

function buildSample(t) {
    var e = t;
    var a = "en", n = "zh";
    var r = {};
    if (r.tplData = {}, r.tplData.to_lang = n, e["double"] = e["double"].replace(/\\'/g, "'"), e.single = e.single.replace(/\\'/g, "'"), e["double"] = e["double"].replace(/[‘|’]/g, "'"), e.single = e.single.replace(/[‘|’]/g, "'"), e["double"]) {
        var u = this.getDoubleSample(e["double"]);
        r.tplData["double"] = u["double"], r.tplData.senData = u.senData, s = r;
    }
    if (e.single) {
        e.single = $.parseJSON(e.single), e.senData2 = [];
        for (var g = 0, p = e.single.length; p > g; g++) {
            var d, m = "";
            "zh" === n ? d = e.single[g][0] : "en" === n && (d = e.single[g][1]);
            for (var c = 0, h = d.length; h > c; c++)
                m += d[c][0], d[c][3] && (m += d[c][3]);
            m = encodeURIComponent(m), e.senData2[g] = m;
            var v = e.single[g][1];
            if (/^http\:\/\//.test(v)) {
                v = v.replace(/^http\:\/\//, "");
                var f = v.indexOf("/");
                e.single[g][2] = f > 0 ? v.substr(0, f) : v;
            } else
                e.single[g][2] = e.single[g][1], e.single[g][1] = "#";
        }
        r.tplData.single = e.single, r.tplData.senData2 = e.senData2;
    }
    return r.tplData;
}

function getDoubleSample(t) {
    var n = "zh";
    var e = {};

    e["double"] = $.parseJSON(t), e.senData = [];
    for (var a = !0, s = 0, l = e["double"].length; l > s; s++) {
        var i, o = "";
        "zh" === n ? i = e["double"][s][0] : "en" === n && (i = e["double"][s][1]);
        for (var r = 0, g = i.length; g > r; r++)
            o += i[r][0], i[r][4] && (o += i[r][4]);
        o = encodeURIComponent(o), e.senData[s] = o, a && $.inArray(e["double"][s][2], u) < 0 && (e["double"][s].isFirstNetSt = !0, a = !1);
        var p = e["double"][s][2];
        if (/^https?\:\/\//.test(p)) {
            p = p.replace(/^https?\:\/\//, "");
            var d = p.indexOf("/");
            e["double"][s][3] = d > 0 ? p.substr(0, d) : p;
        } else
            e["double"][s][3] = e["double"][s][2], e["double"][s][2] = "#";
    }
    return e;
}
------------------------------------------------------
var liju = {
      "double": "[[[[\"Some\",\"w_0\"............................."
      "tag": [
                 "截至"
      ],
     "single": "[[[[\"\\\"\",\"w_0\",0],[................................."
}

/*
 var txt = getDoubleSample(liju.double);
 var t = "", x, y;
for(x in txt["senData"]){
y = Number(x) + 1;
t += y + ". "+ txt["senData"][x] + "<(转义)br(转义)>"; }
t = decodeURIComponent(t);
$("#demo").html(t);
 */
var txt = buildSample(liju);
var t = "", x, y;

for (x in txt["senData2"]) {
y = Number(x) + 1;
 t += y + ". " + txt["senData2"][x] + "<(转义)br(转义)>"; }
t = decodeURIComponent(t);
$("#demo").html(t);

No comments:

Post a Comment