午夜国产狂喷潮在线观看|国产AⅤ精品一区二区久久|中文字幕AV中文字幕|国产看片高清在线

    小米商城搶購時的JavaScript代碼,分析一下
    來源:易賢網(wǎng) 閱讀:1609 次 日期:2015-03-18 11:17:26
    溫馨提示:易賢網(wǎng)小編為您整理了“小米商城搶購時的JavaScript代碼,分析一下”,方便廣大網(wǎng)友查閱!

    小米搶購時的JS代碼,分析一下吧,返回的ajax代碼:

    hdcontrol({"stime":1381645438,"status":{"allow":false,"miphone":{"hdstart":false,"hdstop":false,"hdurl":"","duration":null},"mibox":{"hdstart":false,"hdstop":false,"hdurl":"","duration":null}}})

    function forNum(a){

    return 10>a?"0"+a:a

    }

    function countdown(a,b){

    var c=new Date(b).getTime()/1e3,

    d=c-a,

    e=parseInt(d%60),

    f=parseInt(d/60%60),g=parseInt(d/3600%24),

    h=parseInt(d/3600/24),

    i=[e.toString(),

    f.toString(),

    g.toString()];

    return 0>=d?["00小時00分00秒",!0]:h>0?(window._timestr=h+"天"+forNum(i[2])+"時"+forNum(i[1])+"分"+forNum(i[0])+"秒",[h+"<span>天</span>"+forNum(i[2])+"<span>時</span>"+forNum(i[1])+"<span>分</span>"+forNum(i[0])+"<span>秒</span>",!1]):(window._timestr=forNum(i[2])+"時"+forNum(i[1])+"分"+forNum(i[0])+"秒",[forNum(i[2])+"<span>時</span>"+forNum(i[1])+"<span>分</span>"+forNum(i[0])+"<span>秒</span>",!1])}

    function WebEventTrigger(a,b){

    try{

    if(WE&&WE.trigger)

    return"string"!=typeof b&&(b=JSON.stringify(b)),WE.trigger(a,b)

    }catch(c){}

    return!1

    }

    function isApp(){

    try{

    if(WE)return!0

    }catch(a){}

    return!1

    }

    var quickBuy={init:function(){

    var a=this;

    this.config={},

    this.config.hdurl={miphone:"m3/840410D8656D74E5F334591BD8A408A726799AEC13477D90B5E48DAD36547351/4334F49A1EE391261005E8AC5A0C9D2FDA23BB72A2D20AB3F58343496FD4983D/tip_SaledOverAll.html",mibox:"tv/B1CF7B57BFEAE1EBC37700694C123D894C668BF11F6F25D59311FD36942B3D6A/130F1B18D11F53CA1D0147B24E926C5A9B7676E57BE3D47959D6557545E8A339/tip_SaledOverAll.html"

    },

    this.config.mode="",

    this.mode={miphone:!1,mibox:!1},

    this.modeModals={miphone:"#modal_miphone",mibox:"#modal_mibox"},

    this.modeCookies={miphone:"xm_hd_so_phone",mibox:"xm_hd_so_box"},

    this.config.startDate=+new Date("10/15/2013 12:00:00"),

    this.maskLoad=$("#maskLoad"),

    this.config.minSignTime=120,

    this.results=null,

    this.timer=null,

    this.timeCount=Math.floor(Math.abs(10*Math.random()-5))+5;

    var b=!0;

    for(var c in this.mode)

    $.cookie(this.modeCookies[c])||(b=!1),$.cookie(this.modeCookies[c])&&this.saleOut();

    b||($.cookie("xm_diff_hd")?(this.config.serverTime=this.localTime()+parseInt($.cookie("xm_diff_hd"),10),this.config.serverTime>=parseInt(this.config.startDate/1e3,10)?$.cookie("xm_hd_so_phone")&&$.cookie("xm_hd_so_box")||this.getData(!0,function(){a.goBuy()}):this.launch()):this.getData())},getData:function(a,b){

    var c=this,a=a||null;

    b&&(b=b),

    $.ajax({

    ",

    dataType:"jsonp",

    jsonpCallback:"hdcontrol",

    timeout:7e3,

    beforeSend:function(){

    c.maskLoad.css("display","block")},

    error:function(){

    c.maskLoad.css("display","none"),

    alert("服務(wù)器壓力山大,請您重新刷新頁面!")

    },

    success:function(d){

    if(c.maskLoad.css("display","none"),"undefined"==typeof d)

    return alert("服務(wù)器壓力山大,請您重新刷新頁面!"),

    void 0;

    if(c.results=d,a||(c.config.serverTime=c.results.stime),!$.cookie("xm_diff_hd")){

    var e=parseInt(c.config.serverTime-c.localTime(),10);

    $.cookie("xm_diff_hd",e,{

    path:"/",

    domain:".xiaomi.com",

    expires:1

    })

    }

    if(a){

    c.initialData();

    for(var f in c.mode)

    if(c.config[f].hdstart===!1&&c.config[f].hdstop===!0){

    var g=c.modeCookies[f];

    $.cookie(g,1,{path:"/",domain:".xiaomi.com",expires:1}),

    c.saleOut()

    }else b&&b.call()

    }

    a||c.launch()

    }})},

    initialData:function(){

    this.config.allow=this.results.status.allow,

    this.config.mibox=this.results.status.mibox,

    this.config.miphone=this.results.status.miphone

    },

    launch:function(){

    this.timeStart(),

    this.countdown()

    },

    timeStart:function(){

    var a=this,

    b=1e3*a.config.serverTime,

    c=a.config.startDate,

    d=c-1e3*60*a.config.minSignTime;

    b>=d&&c>b&&!isApp()?

    $.cookie("userId")?

    ($("#view_button").css("visibility","hidden"),

    $("#purchase_btn_1").html('<a href="" class="btn_buy">活動詳情</a>'),

    $("#purchase_btn_2").html('<a href="javascript:;" class="btn_buy btn_02">已經(jīng)登錄</a>')):a.toLogin():b>=c&&a.toBuy()

    },

    toLogin:function(){

    $("#view_button").css("visibility","hidden"),

    $("#purchase_btn_1").html('<a href="" class="btn_buy">活動詳情</a>'),

    $("#purchase_btn_2").html('<a href="javascript:;" class="btn_buy btn_02">提前登錄</a>'),

    $("#purchase_btn_2").find(".btn_02").on("click",function(){

    WebEventTrigger("login",null)||(window.location.href="))}

    )},

    countdown:function(){

    var a=this,

    b=null,

    c=a.config.startDate;

    b=a.config.serverTime?a.config.serverTime:parseInt(+new Date/1e3,10);

    var d=c-1e3*60*a.config.minSignTime,

    e=setInterval(function(){

    var f=countdown(b,c);

    f[1]?(clearInterval(e),$("#countdown").css("display","none"),a.toBuy()):(1e3*b!=d||isApp()||($.cookie("userId")?($("#view_button").css("visibility","hidden"),

    $("#purchase_btn_1").html('<a href="" class="btn_buy">活動詳情</a>'),

    $("#purchase_btn_2").html('<a href="javascript:;" class="btn_buy">已經(jīng)登錄</a>')):a.toLogin()),b++),

    $("#countdown").html(f[0])},1e3)},

    toBuy:function(){

    var a=this;

    a.goBuy();

    var b=a.modeModals[a.config.mode];

    $(b).find(".close").on("click",function(){

    $(b).css("display","none"),

    window.clearTimeout(a.timer),

    a.timer=null})},

    saleOut:function(){

    var a={miphone:"#purchase_btn_2",mibox:"#purchase_btn_1"},

    b={miphone:""},

    c={miphone:"支付小米手機3",mibox:"支付小米電視"};

    for(var d in this.mode)

    $.cookie(this.modeCookies[d])&&($(a[d]).html('<a href="'+b[d]+'" class="btn_buy">'+c[d]+"</a>"),

    $(this.modeModals[d]).is(":visible")&&$(this.modeModals[d]).find(".close").click())},

    localTime:function(){

    var a=parseInt(+new Date/1e3,10);

    return a

    },

    toProcess:function(a){

    var b=this,

    c=b.timer,

    d=b.timeCount||10,e=$(b.modeModals[a]).find(".re_countdown"),

    f=$(b.modeModals[a]).find(".modal_btn"),

    g=function(){0==d?(f.html('<a href="javascript:;" class="into_buy_btn">進(jìn)入活動</a>'),

    b.toBuyGo(b.config.mode),

    c&&window.clearTimeout(c),

    c=null):(e.html("("+d+")"),

    d--,

    b.timer=window.setTimeout(function(){g()},1e3))};

    c&&window.clearTimeout(c),g()},

    goBuy:function(){

    var a=this,

    b={miphone:"購買小米手機3",mibox:"購買小米電視"},

    c={miphone:"#purchase_btn_2",mibox:"#purchase_btn_1"};

    for(var d in a.mode)

    $.cookie(a.modeCookies[d])||($(c[d]).html('<a href="javascript:;" class="btn_buy btn_buy_go" data-type="'+d+'">'+b[d]+"</a>"),

    $(c[d]).is(":hidden")&&$(c[d]).css("display","block"));

    $("#open_button").find(".btn_buy_go").on("click",function(){a.mode[$(this).attr("data-type")]=!0;

    var b=a.config.mode=$(this).attr("data-type");

    if($.cookie("userId"))a.getData(!0,function(){

    $(a.modeModals[b]).css("display","block"),

    $(a.modeModals[b]).find(".close").on("click",function(){

    $(a.modeModals[b]).css("display","none"),window.clearTimeout(a.timer),a.timer=null}),a.toProcess(b)});

    else{if(WebEventTrigger("login",null))return;

    window.location.href=")}})},

    toBuyGo:function(a){

    var b=this;

    window.clearTimeout(b.timer),

    b.timer=null,

    $(b.modeModals[a]).find(".modal_btn").find(".into_buy_btn").on("click",function(c){c.preventDefault(),b.getData(!0,function(){

    if($(b.modeModals[a]).css("display","block"),b.config.allow)if(b.config[a].hdurl){

    var c="";

    window.setTimeout(function(){window.location.href=c},500)

    }else{

    var d="];

    window.setTimeout(function(){window.location.href=d},500)

    }else if(

    b.config[a].hdstart===!1&&b.config[a].hdstop===!0){

    var d="];

    window.setTimeout(function(){window.location.href=d},500)

    }else $(b.modeModals[a]).find(".modal_btn").html('<a href="javascript:;" class="re_enter">重新進(jìn)入<span class="re_countdown"></span></a>'),

    b.toProcess(a)

    })})}};

    更多信息請查看IT技術(shù)專欄

    更多信息請查看腳本欄目
    易賢網(wǎng)手機網(wǎng)站地址:小米商城搶購時的JavaScript代碼,分析一下
    由于各方面情況的不斷調(diào)整與變化,易賢網(wǎng)提供的所有考試信息和咨詢回復(fù)僅供參考,敬請考生以權(quán)威部門公布的正式信息和咨詢?yōu)闇?zhǔn)!

    2025國考·省考課程試聽報名

    • 報班類型
    • 姓名
    • 手機號
    • 驗證碼
    關(guān)于我們 | 聯(lián)系我們 | 人才招聘 | 網(wǎng)站聲明 | 網(wǎng)站幫助 | 非正式的簡要咨詢 | 簡要咨詢須知 | 新媒體/短視頻平臺 | 手機站點 | 投訴建議
    工業(yè)和信息化部備案號:滇ICP備2023014141號-1 云南省教育廳備案號:云教ICP備0901021 滇公網(wǎng)安備53010202001879號 人力資源服務(wù)許可證:(云)人服證字(2023)第0102001523號
    云南網(wǎng)警備案專用圖標(biāo)
    聯(lián)系電話:0871-65099533/13759567129 獲取招聘考試信息及咨詢關(guān)注公眾號:hfpxwx
    咨詢QQ:1093837350(9:00—18:00)版權(quán)所有:易賢網(wǎng)
    云南網(wǎng)警報警專用圖標(biāo)