紅米手機搶購的js代碼
以下就是小米搶購時的JS代碼,分析一下就可以用它實現(xiàn)一個紅米搶購軟件,大家根據(jù)這個代碼實現(xiàn)自己想要的功能吧!
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){
varc=newDate(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()];
return0>=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])}
functionWebEventTrigger(a,b){
try{
if(WE&&WE.trigger)
return"string"!=typeofb&&(b=JSON.stringify(b)),WE.trigger(a,b)
}catch(c){}
return!1
}
functionisApp(){
try{
if(WE)return!0
}catch(a){}
return!1
}
varquickBuy={init:function(){
vara=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=+newDate("10/15/201312: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;
varb=!0;
for(varcinthis.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){
varc=this,a=a||null;
b&&(b=b),
$.ajax({
url:"http://tc.hd.xiaomi.com/hdget",
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"==typeofd)
returnalert("服務(wù)器壓力山大,請您重新刷新頁面!"),
void0;
if(c.results=d,a||(c.config.serverTime=c.results.stime),!$.cookie("xm_diff_hd")){
vare=parseInt(c.config.serverTime-c.localTime(),10);
$.cookie("xm_diff_hd",e,{
path:"/",
domain:".xiaomi.com",
expires:1
})
}
if(a){
c.initialData();
for(varfinc.mode)
if(c.config[f].hdstart===!1&&c.config[f].hdstop===!0){
varg=c.modeCookies[f];
$.cookie(g,1,{path:"/",domain:".xiaomi.com",expires:1}),
c.saleOut()
}elseb&&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(){
vara=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('<aclass="btn_buy"),
b.toProcess(a)
})})}};
相關(guān)文章
基于slideout.js實現(xiàn)移動端側(cè)邊欄滑動特效
這篇文章主要為大家詳細介紹了基于slideout.js實現(xiàn)移動端側(cè)邊欄滑動特效,具有一定的參考價值,感興趣的小伙伴們可以參考一下2016-11-11使用JavaScript獲取掃碼槍掃描得到的條形碼的思路代碼詳解
這篇文章主要介紹了使用JavaScript獲取掃碼槍掃描得到的條形碼的思路代碼詳解,本文通過示例代碼給大家介紹的非常詳細,對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下2020-06-06為什么說JavaScript預(yù)解釋是一種毫無節(jié)操的機制詳析
這篇文章主要給大家介紹了關(guān)于為什么說JavaScript預(yù)解釋是一種毫無節(jié)操的機制的相關(guān)資料,文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面來一起看看吧2018-11-11微信小程序?qū)崿F(xiàn)密碼顯示與隱藏的睜眼閉眼功能
這篇文章主要介紹了微信小程序?qū)崿F(xiàn)密碼顯示與隱藏的睜眼閉眼功能,文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧2023-02-02