Tmall抢红包,抓猫,砸金砖的客户端JS代码

下面的代码是前阵子天猫抢红包,抓猫和砸金砖的客户端代码,我做了部分注释。

/*
TMALL event code
MitchellChu采集,仅供个人研究之用
*/
(function(){
Volcano = {};
Volcano.Message = {};
KISSY.mix(Volcano.Message, KISSY.EventTarget);
//数据总线
Volcano.Bus = {
    isStart: true,
    isEnd: false,
    timeObj: {
        day: '17',
        hour: '20',
        minute: '12',
        second: '53'
    },
    timeNow: 1339935173,   
    timeEnd: 1339938000,  
    timeNext: 1339984800,
    timeOut: 1339941599,
    hourEnd: 21,
    hourStart: 10,
    leftBagNum: 200000,
    awardCode: '&time=1339935173&checkCode=/*hash code*/',
    bagTotal: 200000,  
    bagCycle: 30,   
    detailTitleMap : {
        'await'   : '离开抢还有',
        'nervous' : '离下一轮开抢还有',
        'crazy'      : '疯抢进行中',
        'tomorrow': '新一轮的红包疯抢将于6月18号早上10点开始'
    }
};
window['g_config'] = window.g_config || {};
window['g_config'].flhstime=0.8;

// 倒计时
Volcano.Countdown=(
function(b){
    var f=window;
    var g="vol-countdown";
    function e(i){
        if(/^\d+$/.exec(i)){return i-0}
        return 0
    }
    function h(i){return i<10?("0"+i):(""+i)}
    function c(l){
        var k=l.el;
        k.className=k.className+" "+g;
        var j=function(m){
            if(m<10){return["0",""+m]}
            else{return(""+m).split("")}
        };
        var i=function(o){
            if(o.day>0){o.hour+=o.day*24}
            var m=j(o.hour);
            var p=j(o.minute);
            var n=j(o.second);
            k.innerHTML='<span class="vol-countdown-part vol-countdown-hour"><strong class="vol-countdown-digital vol-countdown-a">'+m[0]+'</strong><strong class="vol-countdown-digital vol-countdown-b">'+m[1]+'</strong><span class="vol-countdown-unit">:</span></span><span class="vol-countdown-part vol-countdown-minute"><strong class="vol-countdown-digital vol-countdown-a">'+p[0]+'</strong><strong class="vol-countdown-digital vol-countdown-b">'+p[1]+'</strong><span class="vol-countdown-unit">:</span></span><span class="vol-countdown-part vol-countdown-second"><strong class="vol-countdown-digital vol-countdown-a">'+n[0]+'</strong><strong class="vol-countdown-digital vol-countdown-b">'+n[1]+"</strong></span>"
        };
        l.on("timeing",i)
    }
    function a(j,i){
        j=b.get(j);
        if(!j){return}
        this.el=j;
        this._options=i;
        this._options.timeEnd=this._options.timeEnd||j.getAttribute("data-end")-0;
        this._options.timeNow=this._options.timeNow||j.getAttribute("data-now")-0;
        this._exp={};
        this._timePass=0;
        c(this)
    }
    b.augment(a,b.EventTarget,{
        run:function(){
            var t=this;
            var u=t._options;
            var p=u.timeEnd-u.timeNow;
            var r=setTimeout;
            var s,n,m,l;
            var i=function(){
                return{day:s,left:p,hour:n,minute:m,second:l,timeStr:t.date("{H}:{i}:{s}")}
            };
            l=p;
            var q=24*60*60;
            s=Math.floor(l/q);
            l-=q*s;
            n=Math.floor(l/3600);
            l-=n*3600;
            m=Math.floor(l/60);
            l-=60*m;
            if(p<=0){
                t.fire("timeOut",i());
                return
            }
            var k=1000;
            var o=new Date().getTime();
            var j=function(){
                var y=i();
                t.fire("timeing",y);
                var B=t._exp,w,D,x,v=y.timeStr;
                for(w in B){
                    D=B[w];
                    if(D.re.exec(v)){
                        x=D.callback;
                        for(var A=0,C=x.length;A<C;A++){
                            x[A].call(f,y)
                        }
                    }
                }
                if(0==p){t.fire("timeEnd",y);return}
                l-=1;
                p-=1;
                if(-1===l&&(0<m||0<n||0<s)){l=59;m--}
                if(-1===m&&(0<n||0<s)){m=59;n--}
                if(-1===n&&(0<s)){n=23;s--}
                t._timePass++;
                o+=k;
                var z=o-new Date().getTime();
                r(j,z>0?z:0)
            };
            j()
        },
        date:function(m){
            var j=this;
            var l=j._options;
            m=m||"{Y}-{m}-{d}{H}:{i}:{s}";
            var i=(l.timeNow+j._timePass)*1000;
            var k=new Date(i);
            return m.replace(/{(\w+)}/g,function(o,n){
                switch(n){
                    case"Y":return k.getFullYear();
                    case"m":return h(k.getMonth()+1);
                    case"d":return h(k.getDate());
                    case"H":return h(k.getHours());
                    case"i":return h(k.getMinutes());
                    case"s":return h(k.getSeconds())
                }
            })
        },
        when:function(i,j){
            var l=i.replace(/{\w+}/g,"\\d+");
            var k=this._exp[l]||{re:new RegExp(l),exp:i,callback:[]};
            k.callback.push(j);
            this._exp[l]=k
        },
        removeWhen:function(l,m){
            var p=l.replace(/{\w+}/g,"\\d+");
            var o=this._exp[p];
            if(o&&o.callback){
                if(m){
                    var n=[],q=o.callback;
                    for(var k=0,j=q.length;k<j;k++){
                        if(q[k]!=m){n.push(q[k])}
                    }
                    o.callback=n
                }
                else{o.callback=[]}
            }
        }
    });
    return a
})(KISSY);

// 抓猫的代码
Volcano.cat=(
function(f,h){
    var m=f.DOM,l=f.Event,i=f.Anim;
    var j=m.create('<div id="J_VolCat" class="vol-cat">');
    var g=m.create('<div id="J_VolCatBody" class="vol-cat-body" style="display:none;position:absolute;">');
    g.appendChild(j);
    var e=null;
    var a=null;
    var k=null;
    var c=null;
    var b={
        run:function(){
            this.setPos();
            this.show()
        },
        setPos:function(){
            m.css(g,"top",Math.round(Math.random()*(m.viewportHeight()-120))+"px");
            m.css(g,"left",Math.round(Math.random()*(m.viewportWidth()-120))+"px")
        },
        catched:function(){
            this.hide();
            Volcano.getLottery("cat",function(n){})
        },
        show:function(){
            var n=this;
            var o=m.get("#J_VolCat");
            if(!o){document.body.appendChild(g)}
            m.css(g,"display","block");
            this.status="showing";
            e=i(
                "#J_VolCat",
                {top:"0"},
                0.3,
                "easyInStrong",
                function(){
                    clearTimeout(c);
                    clearTimeout(k);
                    c=setTimeout(function(){n.hide()},(Math.random()*3)*1000);
                    n.status="showed"
                });//i=KISSY.Anim(...);
            e.run()
        },
        hide:function(){
            var n=this;
            this.status="hiding";
            e=i(
                "#J_VolCat",
                {top:"74px"},
                0.3,
                "easyOutStrong",
                function(){
                    m.css(g,"display","none");
                    clearTimeout(c);
                    clearTimeout(k);
                    n.afterHide&&n.afterHide();
                    n.status="hided"
                }
            );
            e.run()
        },
        start:function(n){
            n=n||60;
            n=n*1000;
            var o=this;
            var q=2000;
            var p=1;
            o.run();
            o.afterHide=function(){
                k=setTimeout(function(){
                    if(o.status=="hided"){o.run()}
                },(Math.random()*1)*1000)
            };
            a=setInterval(function(){
                n-=q;
                if(n<=2000){
                    delete o.afterHide;
                    clearInterval(a)
                }
            },2000)
        },
        stop:function(){
            if(e){e.stop()}
            clearInterval(a);
            clearTimeout(c);
            clearTimeout(k);
            m.css(g,"display","none")
        },
        init:function(){
            var n=this;
            l.on(g,"click",function(){n.catched()})// 监听猫被抓的事件:click
        }
    };
    b.init();
    return b
})(KISSY,window);

var Volcano=Volcano||{}; //初始化Volcano

Volcano.rate=(window.g_config&&window.g_config.flhstime)||1;
Volcano.userTimes=0;
Volcano.mood={
    value:0,
    moodMap:["yeah","normal","sad","shock","angry","thunder"],
    msgMap:["success",
        "\u672a\u62bd\u4e2d\u7ea2\u5305\u56fa\u7136\u53ef\u60dc\uff0c\u4f46\u501f\u6b64\u65f6\u673a\u4fee\u70bc\u4fee\u70bc\u6027\u60c5\u662f\u6781\u597d\u7684!",
        "\u7ea2\u5305\u662f\u6211\u4eec\u7684\uff0c\u4e5f\u662f\u4f60\u4eec\u7684\uff0c\u4f46\u5f52\u6839\u7ed3\u5e95\u662f\u4f60\u4eec\u7684!",
        "\u53d1\u751f\u8fd9\u79cd\u4e8b\u60c5\uff0c\u5927\u5bb6\u90fd\u4e0d\u60f3\u7684\uff0c\u505a\u4eba\u6700\u91cd\u8981\u7684\u5c31\u662f\u5f00\u5fc3\uff0c\u6211\u716e\u9762\u7ed9\u4f60\u5403\u554a!",
        "\u6211\u7684\u7ea2\u5305\u5462\uff1f\uff01\u6211\u7684\u7ea2\u5305\u5462\uff1f\uff01\u5305\u5927\u4eba...",
        "\u8ddf\u795e\u4e5d\u4e0a\u5929\u8f6c\u4e2a\u8fd0\u518d\u6765\u62bd\uff01"],
    add:function(){this.value+=1},
    reset:function(){this.value=0},
    getLevel:function(){
        if(this.value===0){return 0}
        else{
            if(this.value<=2){return 1}
            else{
                if(this.value<=5){return 2}
                else{
                    if(this.value<=9){return 3}
                    else{
                        if(this.value<=15){return 4}
                        else{return 5}
                    }
                }
            }
        }
    },
    setRandom:function(){this.random=1+Math.floor(Math.random()*5)},
    getRandom:function(){
        if(!this.random){this.setRandom()}
        S.log("mood random: "+this.random);
        return this.random
    },
    getMood:function(){return this.moodMap[this.getLevel()]},
    getMsg:function(){return this.msgMap[this.getLevel()]},
    getMoodByRandom:function(){return this.moodMap[this.getRandom()]},
    getMsgByRandom:function(){return this.msgMap[this.getRandom()]}
};

Volcano.Message.on(
    "showCrazy",
    function(){Volcano.mood.reset()}
);

Volcano.Msgs={
    cat:{
        success:"\u83b7\u5f97<span class='vol-dialog-hi'>${val}</span>\u7ea2\u5305",
        fail:"\u672a\u4e2d\u5956\u7ee7\u7eed\u6349\u5427\uff01"
    },
    bag:{
        success:"\u83b7\u5f97<span class='vol-dialog-hi'>${val}</span>\u7ea2\u5305",
        fail:"\u5dee\u4e00\u70b9\u5c31\u62a2\u5230\u4e86\uff0c\u518d\u6765\u4e00\u6b21\u5427\u3002",
        over:"\u522b\u7070\u5fc3,\u4e0b\u4e2a\u6574\u70b9\u518d\u6765\u5427"
    }
};

Volcano.shareText="#\u4e0a\u5929\u732b\uff0c\u5c31\u8d2d\u4e86# 4000\u4e07\u7ea2\u5305\u5927\u6d3e\u9001\uff016\u670815\u65e5\u81f318\u65e5\uff0c\u8f93\u5165tmall.com\u767b\u9646\u5929\u732b\uff0c\u767e\u4e07\u4efd5\u5143\u300120\u5143\u3001100\u5143\u30011000\u5143\u30013000\u5143\u30014999\u5143\u7b49\u591a\u8fbe9\u6863\u9762\u989d\u7684\u7ea2\u5305\u5168\u573a\u65e0\u95e8\u69db\u53d1\u9001\uff0c\u5168\u57ce\u65e0\u9650\u5236\u4f7f\u7528\u3002\u8d76\u7d27\u6765\u62a2\u5427\uff01";

//抽奖核心对象
Volcano.getLottery=function(b){
    var j=b.Event,a=b.DOM;
    var e='<dl class="vol-tip"><dt>\u63d0\u793a\uff1a</dt><dd>1.\u53ea\u6709\u7ed1\u5b9a\u624b\u673a\u624d\u80fd\u6536\u5230\u7ea2\u5305\u54e6\u3002<a href="http://110.taobao.com/home/myInfo.htm?spm=3.278815.267595.1" target="_blank">\u67e5\u770b\u7ed1\u5b9a\u60c5\u51b5></a></dd><dd>2.\u6211\u4eec\u5c06\u4e8e\u5f53\u592924:00\u524d\uff0c\u5c06\u7ea2\u5305\u53d1\u9001\u5230\u60a8\u7684\u652f\u4ed8\u5b9d\u5e10\u6237\u3002</dd></dl>';
    var c='<div class="vol-dialog-card"><p>\u5929\u732b\u8fbe\u4eba\u4eab\u5929\u732b\u9000\u8d27\u4fdd\u969c\u5361<br><a target="_blank" href="http://vip.tmall.com/vip/privilege.htm?spm=3.278815.267595.2&layer=activation&amp;priv=returngurantee">\u70b9\u6b64\u67e5\u770b></a></p></div>';var i='<div class="vol-dialog ${type}"><s class="vol-dialog-face-${mood}"></s><div class="vol-dialog-${type}"></div><div class="vol-dialog-msg">${msg}</div>${share}${left}${other}<i class="vol-dialog-cat"></i> <a class="vol-dialog-close">X</a></div>';
    var h=false;
    var f=null;
    //核心对象
    var g={
        showDialog:function(n){
            n.other=n.other||e;
            var o=f,l=g.renderData(i,n);
            if(!o){
                o=document.createElement("div");
                var m=b.get("#J_Vol .vol-bg")||document.body;
                m.appendChild(o);
                j.on(o,"click",function(q){
                    var p=q.target;
                    if(a.hasClass(p,"vol-dialog-close")){
                        o.innerHTML="";
                        Volcano.Message.fire("closeDialog");
                        q.preventDefault()
                    }
                    else{
                        if(a.hasClass(p,"vol-dialog-share")){
                            g.share();
                            q.preventDefault()
                        }
                    }
                })
            }
            o.innerHTML=l;
            o.style.height="100px";
            var k=new b.Anim(b.get(".vol-dialog",o),{top:"50px"},0.3,"easeOutStrong"); //动画弹出对话框
            k.run();
            f=o
        },
        renderData:function(l,k){return l.replace(/\$\{(.*?)\}/g,function(n,m){return k[m]||""})},
        checkGetLottery:function(k,l){
            if(b.get("#login-info .j_UserNick")||h){g.getlottery(k,l)}
            else{g.loginGetLottery(k,l)}
        },
        loginGetLottery:function(k,l){
            TML.use("minilogin,overlay/css/overlay.css",function(m,n){
                n=n||m.MiniLogin;
                n.show(function(){
                    h=true;
                    TB._isMemberInfoReady=false;
                    TB._isLoginStatusReady=false;
                    TB.Global.writeLoginInfo();
                    g.getlottery(k,l)
                },
                {check:false})
            })
        },
        share:function(){window.open("http://service.weibo.com/share/share.php?url="+encodeURIComponent(location.href)+"&title="+encodeURIComponent(Volcano.shareText)+"&pic=http://img04.taobaocdn.com/tps/i4/T1yBzjXf8qXXXzmpoC-540-260.jpg","","height=700, width=650")},
        // 这里是抽奖的关键!!!
        getlottery:function(m,q){
            g.showDialog({msg:"<p style='padding: 15px;'>\u6b63\u5728\u4e3a\u60a8\u62bd\u5956...</p>"});
            var n=Math.random();
            b.log("currentRate: "+n);
            b.log("user times: "+Volcano.userTimes);
            b.log("testRate: "+Volcano.rate);
            if(n<Volcano.rate&&Volcano.userTimes<12){
                var o="http://promotion.taobao.com/tmall/furinkazan.do?we=1",l=false;
                o+=Volcano.Bus.awardCode;
                o+="&ua="+encodeURIComponent(ua);
                o+="&RandomNum="+new Date().getTime();
                o+="&stra="+(m==="bag"?"1":"2");
                var k="tml"+b.guid();
                j.on(window,"error",function(r){
                    l=true;
                    g.error({isSuccess:"F",error:"E000"},m,q);
                    j.remove(window,"error",arguments.callee)
                });
                var p=function(r){
                    l=true;
                    if(r.isSuccess==="T"){g.success(r,m,q)}
                    else{g.error(r,m,q)}
                    if(r.param){Volcano.userTimes=r.param.times||0}
                };
                b.io({
                    url:o,
                    type:"get",
                    dataType:"jsonp",
                    jsonpCallback:k,
                    success:p,
                    error:function(){
                        l=true;
                        g.error({isSuccess:"F",error:"E000"},m,q)
                    }
                });
                Volcano.Message.fire("stat",{params:"pos=request"});
                UA_Opt.Token=new Date().getTime()+":"+Math.random();
                UA_Opt.reload();
                setTimeout(function(){
                    if(!l){
                        l=true;
                        p=function(){};
                        g.error({isSuccess:"F",error:"E000"},m,q)
                    }
                },3000)
            }
            else{g.error({isSuccess:"F",error:"E000"},m,q)}
        },
        success:function(l,k,m){
            Volcano.mood.reset();
            g.showDialog({
                type:k+"-ok",
                msg:g.renderData(Volcano.Msgs[k]["success"],{val:l.user.name}),
                share:'<a class="vol-dialog-share">\u5206\u4eab\u5fae\u535a></a>',
                left:k=="bag"&&(g.getLeft(l)<Volcano.Bus.bagTotal)?'<p class="vol-dialog-left">\u672c\u65f6\u6bb5\u5269\u4f59 <b>'+g.getLeft(l)+"</b> \u4e2a\u7ea2\u5305</p>":"",
                mood:Volcano.mood.getMood()
            });
            m(l);
            Volcano.Bus.leftBagNum=g.getLeft(l);
            b.Cookie.set("leftBagNum",Volcano.Bus.leftBagNum);
            b.log("leftBagNum set by lottery : success callback: "+g.getLeft(l))
        },
        error:function(n,k,o){
            Volcano.mood.add();
            if(n.param&&n.param.prizeBestow){
                Volcano.Bus.leftBagNum=g.getLeft(n);
                b.Cookie.set("leftBagNum",Volcano.Bus.leftBagNum);
                b.log("leftBagNum set by lottery : error callback: "+g.getLeft(n))
            }
            var m=n.error;
            if(m==="E014"){g.loginGetLottery(k,o)}
            else{
                if(!Volcano.Bus.inSafeMin&&k==="bag"&&n.param&&n.param.prizeBestow>=Volcano.Bus.bagTotal){
                    g.showDialog({
                        type:"over",
                        msg:Volcano.Msgs[k]["over"],
                        other:c});
                    o(n)
                }
                else{
                    var l=n.param&&n.param.prizeBestow&&g.getLeft(n)>0?g.getLeft(n):Volcano.Bus.leftBagNum;
                    Volcano.mood.setRandom();
                    g.showDialog({
                        type:"fail",
                        msg:Volcano.mood.getMsgByRandom(),
                        left:k=="bag"&&(l<Volcano.Bus.bagTotal)?'<p class="vol-dialog-left">\u672c\u65f6\u6bb5\u5269\u4f59 <b>'+l+"</b> \u4e2a\u7ea2\u5305</p>":"",
                        mood:Volcano.mood.getMoodByRandom()});
                    o(n)
                }
            }
        },
        getLeft:function(l){
            var k=Volcano.Bus.bagTotal-l.param.prizeBestow;
            return k>0?k:0
        }
    };
    Volcano.closeDialog=function(){
        if(f){f.innerHTML=""}
    };
    return function(k,l){
        k=k||"bag";
        l=l||function(){};
        if(f){f.innerHTML=""}
        g.checkGetLottery(k,l)
    }
}(KISSY);

//总控制器
Volcano.Controller=(function(i,h){
    var q=i.DOM,v=i.Event,j=i.Cookie;var k;var r=Volcano.Bus;
    var t=r.detailTitleMap;
    var e=q.get("#J_BagBox");
    var c=q.get("#J_Lucky");
    var n=q.get("#J_DetailTitle");
    var s=q.get("#J_CountDown");
    var b=q.get("#J_CatTip");
    var g=q.query("li","#J_VolTimeLine");
    var p=q.get("#J_TopTitle");
    var m={
        init:function(){},
        updateDetailTitle:function(w){n.innerHTML=w},
        goNextRound:function(){
            this.hideBagBox();
            this.showTimer();
            this.updateDetailTitle(t.nervous);
            this.disableLuckyBtn()
        },
        hideLuckyBtn:function(){
            c.style.visibility="hidden"
        },
        showLuckyBtn:function(){this.enableLuckyBtn();c.style.visibility="visible"},
        enableLuckyBtn:function(){q.removeClass(c,"vol-btn-disable");c.disabled="false"},
        disableLuckyBtn:function(){
            if(r.inSafeMin){
                return
            }
            q.addClass(c,"vol-btn-disable");
            c.disabled="true"
        },
        showTimer:function(){s.style.visibility="visible"},
        hideTimer:function(){s.style.visibility="hidden"},
        showBagBox:function(){e.style.visibility="visible"},
        hideBagBox:function(){e.style.visibility="hidden"},
        showCatchCatTip:function(){b.style.visibility="visible";p.style.visibility="hidden"},
        hideCatchCatTip:function(){b.style.visibility="hidden";p.style.visibility="visible"},
        updateTimeline:function(x){
            var w;
            if(x.indexOf(":11:")>-1){w=x.replace(/(\d+:\d+:)\d+/,"$100")}
            x=x.replace(/(\d+):\d+:\d+/,"$1:00:00");
            i.each(g,function(y){
                var z=y.getAttribute("data-time");
                q[(z==x||z==w)?"addClass":"removeClass"](y,"vol-timeline-cur")
            })}
    };
    m.updateTimeline(r.timeObj.hour+":00:00");function u(){
        k=new Volcano.Countdown(s,{timeNow:r.timeNow,timeEnd:r.timeEnd});
        i.log("timer started, timeNow:"+(new Date(r.timeNow*1000))+", timeEnd:"+(new Date(r.timeEnd*1000)));
        r.inFirstReq=false;
        r.isNextGot=false;
        k.on("timeing",function(z){
            var x=z.timeStr.split(":");
            r.timeObj={hour:x[0],minute:x[1],second:x[2]};
            r.inSafeMin=(
            x[1]-0)<=20;
            if(!r.inFirstReq&&!r.inSafeMin){
                r.inFirstReq=true;
                var y="tml"+i.guid();
                i.io({
                    url:"http://promotion.taobao.com/tmall/queryPrizeBestow.do",
                    type:"get",
                    dataType:"jsonp",
                    jsonpCallback:y,
                    success:function(B){
                        if(B.isSuccess===true){
                            var A=B.result&&B.result.prizeBestow;
                            r.leftBagNum=r.bagTotal-A;
                            if(r.leftBagNum<=0){r.leftBagNum=0}
                            i.Cookie.set("leftBagNum",r.leftBagNum);
                            i.log("prizeBestow:"+A);
                            i.log("leftBagNum:"+r.leftBagNum)
                        }
                        if(r.leftBagNum<=0&&!r.inSafeMin){m.goNextRound()}
                    },
                    error:function(){}
                })
            }
            else{
                if(location.href.indexOf("ks-debug")!=-1){
                    var w=location.href.match(/leftBagNum\=(\d+)/);
                    if(w&&w[1]){r.leftBagNum=w[1]}
                }
                if(r.leftBagNum<=0&&!r.inSafeMin){m.goNextRound()}
            }
        });
        if(r.isEnd){m.updateDetailTitle(t.await)}
        else{
            i.each(["11:11:{v}","15:11:{v}","20:11:{v}"],function(w){
                k.when(w,function(x){
                    i.log(1111);
                    m.showCatchCatTip();
                    m.updateTimeline(x.timeStr);
                    Volcano.cat.start();
                    k.removeWhen(w,arguments.callee)
                })
            });
            i.each(["11:12:00","15:12:00","20:12:00"],function(w){
                k.when(w,function(x){
                    m.hideCatchCatTip();
                    m.updateTimeline(x.timeStr);
                    Volcano.cat.stop();
                    Volcano.closeDialog()
                })
            });
            k.when(r.hourEnd+1+":00:00",function(){
                m.updateTimeline("0");
                m.hideBagBox();
                m.showTimer();
                m.updateDetailTitle(t.nervous);
                m.disableLuckyBtn();
                console.log("1")
            })
        }
        k.on("timeEnd",function(w){
            var y=false;
            var x=r.timeOut-r.timeEnd;
            if(x==3600){
                y=true;
                r.timeNow=r.timeEnd;
                r.timeEnd=r.timeNext
            }
            else{
                if(x>=0){
                    r.timeNow=r.timeEnd;
                    r.timeEnd+=3600
                }
                else{return}
            }
            if(r.timeNow>=r.timeOut&&!y){
                r.timeEnd=r.timeNext;
                m.updateDetailTitle(t.tomorrow);
                m.disableLuckyBtn()
            }
            else{
                m.hideTimer();
                m.showBagBox();
                m.showLuckyBtn();
                m.updateDetailTitle(t.crazy);
                m.updateTimeline(w.timeStr);
                Volcano.Message.fire("showCrazy")
            }
            u()});
        k.on("timeing",function(w){
            Volcano.Message.fire("timeing",w)}
        );
        k.run()
    }
    u();
    Volcano.Timer=k;
    var a=[];
    var f;
    Volcano.Message.on("closeDialog",function(){
        var w=a.join("");
        if(w.match(/10(210)*/g)){a.push("2")}
    });
    var o=function(){
        var w=document.createElement("div");
        w.style.cssText="position: absolute; width: 170px; height:68px; left: 405px;top:130px;cursor:pointer;";
        q.insertAfter(w,c);
        v.on(w,"mouseenter",function(){a.push("1")});
        v.on(w,"mouseleave",function(){
            a.push("0");
            if(a.length>49){a=[]}
            this.parentNode.removeChild(this);
            this.onclick=null;
            f=o();
            f.onclick=l
        });
        return w
    };
    var l=function(){
        var w=a.join("");
        if(!w.match(/1(021)*/g)){return}
        if("true"==c.disabled||q.hasClass(c,"vol-btn-disable")){return false}
        Volcano.getLottery("bag",function(x){
            Volcano.Message.fire("bagLotterySuccess",{params:x})
        });
        return false
    };
    f=o();
    v.on(f,"click",l);
    return m
})(KISSY,window);

// 金砖
Volcano.queryCurBrickTime=function(b){
    var j=Volcano.Bus.timeObj;
    var f=[j.hour,j.minute,j.second].join("")-0;
    var h=Volcano.Bus.brickList;
    var a=false;
    var k,e;
    for(var c=0,g=h.length;c<g;c++){
        k=h[c];
        e=h[c+1];
        if(k<=f&&f<e){a=true;break}
    }
    if(a){
        return{cur:k,next:e,idx:c}
    }
};

// KISSY在Page 加载完成的时候处理
KISSY.ready(function(b){
    function a(f,e,i){
        if(!f){return false}
        e=e||location.href;
        i=i||document.title;
        var h=window.external,
            g=window.sidebar,
            c=true;
        if(h&&"AddFavorite" in h){h.AddFavorite(e,i)}
        else{
            if(g&&g.addPanel){g.addPanel(i,e,"")}
            else{
                if(window.opera){
                    f.setAttribute("rel","sidebar");
                    f.href=e;
                    f.title=i
                }
                else{
                    alert("\u60a8\u7684\u6d4f\u89c8\u5668\u4e0d\u652f\u6301\u81ea\u52a8\u6dfb\u52a0\u6536\u85cf\u5939\u529f\u80fd\n\u8bf7\u624b\u52a8\u5c06\u672c\u9875\u6dfb\u52a0\u5230\u6536\u85cf\u5939\uff08\u5feb\u6377\u952e\uff1a"+(navigator.appVersion.indexOf("Mac")>-1?"Cmd":"Ctrl")+"+D)");
                    c=false
                }
            }
        }
        return c
    }
    b.Event.on("#J_AddFavLink","click",function(c){
        c.halt();
        a(this,location.href,"\u5929\u732bTmall.com")
    })
});

// run at start
(function(f){
    var b=KISSY;
    var a=new Image();
    var e=window;
    function c(h){
        var g="";
        if(e.userCookie){g=e.userCookie._nk_||""}
        h.params=h.params||h.toString();
        b.log("stat fired");
        b.log(h);
        a.src="http://www.atpanel.com/tmallhd.1.1?nick="+g+"&"+h.params
    }
    Volcano.Message.on("stat",c);
    KISSY.Event.on("#J_Vol","click",function(g){
        var h=g.target;
        var i=h.getAttribute("data-stat");
        if(i){
            c({params:i})
        }
    })
})();

// RUN at start.
// f = KISSY, i=window
/*
<div id="J_BagBox" class="vol-hongbao">
当前时段: <span>发放红包 <em id="J_BagLeft">200000</em>个</span>
</div>
*/
Volcano.bagleft=(function(f,i){
    var p=f.DOM,n=f.Event,a=f.Cookie,k=f.io;
    var c=p.get("#J_BagLeft"); // 还剩的红包数量
    var e=p.get("#J_BagBox"); // 当前时段的红包信息
    var m=c.parentNode; // span
    var q=Volcano.Message;
    var j=Volcano.Bus;
    var l=j.bagTotal;
    var h=10;
    var g="http://promotion.taobao.com/tmall/queryPrizeBestow.do";
    var b={
        update:function(s){
            var o=this;
            var r="tml"+f.guid();
            f.log("current bagleft: "+j.leftBagNum);
            if(e&&(p.css(e,"visibility")=="visible")){
                k({ url:g,
                    type:"get",
                    dataType:"jsonp",
                    jsonpCallback:r,
                    success:function(t){
                        if(t.isSuccess===true){o.success(t)}
                        else{o.error(t)}
                    },
                    error:function(){o.error(d)}
                })
            }
        },
        render:function(r){
            var s="\u53d1\u653e\u7ea2\u5305";
            var o="\u5269\u4f59\u7ea2\u5305";
            if(r<0){r=l}
            if(isNaN(r)){r=l}
            if(m&&e&&(p.css(e,"visibility")=="visible")){p.html(m,(r==l?s:o)+' <em id="J_BagLeft">'+r+"</em>\u4e2a")}
        },
        success:function(r){
            r=r||{};
            var o=l;
            if(r.result&&r.result.prizeBestow){
                o=j.bagTotal-r.result.prizeBestow;
                this.updateLeftNum(o);
                if(j.inSafeMin){
                    if(o<=0){o=l}
                    f.log("get bagleft success but in safe time")
                }
                f.log("get bagleft success:"+j.leftBagNum)
            }
            this.render(o)
        },
        error:function(o){this.autoDown()},
        autoDown:function(){
            var o=j.leftBagNum;
            if(o>h&&o<l){
                o=o-Math.round(Math.random()*h);
                this.updateLeftNum(o)
            }
            this.render(o)
        },
        updateLeftNum:function(o){
            if(o>0){j.leftBagNum=o}
        },
        reset:function(){
            this.updateLeftNum(l);
            this.render(l)
        },
        init:function(r){
            var o=this;
            var s=0;
            r=r||60;
            q.on("timeing",function(t){
                if(s%2===0){o.autoDown()}
                if(s%r===0){o.update()}
                s+=1
            });
            q.on("showCrazy",function(t){o.reset()});
            n.on("error",function(){o.error()})
        }
    };
    return b
})(KISSY,window);


})();
var ua="";
var UA_Opt=new Object;
UA_Opt.LogVal="ua";
UA_Opt.MaxMCLog=3;
UA_Opt.MaxMPLog=3;
UA_Opt.MaxKSLog=3;
UA_Opt.Token=new Date().getTime()+":"+Math.random();
UA_Opt.SendMethod=8;
UA_Opt.Flag=/*here is a number to flag*/;

从中我们能看到当年的砸金砖我们点的手都断掉了,但是人家5s才一次的请求,你点断手有啥子用?

Monday, June 25, 2012 | Javascript(s)

文章评论

  • # re: Tmall抢红包,抓猫,砸金砖的客户端JS代码
    • ty
    • 6/29/2012 2:56 PM
    试试能不能评论
  • # re: Tmall抢红包,抓猫,砸金砖的客户端JS代码
    • cjl
    • 5/5/2015 9:18 AM
    能不能整一个demo出来方便下载呢。

发表评论

Please add 7 and 4 and type the answer here:

关于博主

  一枚成分复杂的网络IT分子,属于互联网行业分类中的杂牌军。