以下就是小米抢购时的JS代码,分析一下就可以用它实现一个红米抢购软件,大家根据这个代码实现自己想要的功能吧!
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+"天"+forNum(i[2])+"时"+forNum(i[1])+"分"+forNum(i[0])+"秒",!1]):(window._timestr=forNum(i[2])+"时"+forNum(i[1])+"分"+forNum(i[0])+"秒",[forNum(i[2])+"时"+forNum(i[1])+"分"+forNum(i[0])+"秒",!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("服务器压力山大,请您重新刷新页面!")
},
success:function(d){
if(c.maskLoad.css("display","none"),"undefined"==typeofd)
returnalert("服务器压力山大,请您重新刷新页面!"),
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('
$("#purchase_btn_2").html('
},
toLogin:function(){
$("#view_button").css("visibility","hidden"),
$("#purchase_btn_1").html('
$("#purchase_btn_2").html('
$("#purchase_btn_2").find(".btn_02").on("click",function(){
WebEventTrigger("login",null)||(window.location.href="http://m.xiaomi.com/mshopapi/index.php/v1/authorize/sso?client_id=180100031013&callback="+encodeURIComponent(window.location.href))}
)},
countdown:function(){
vara=this,
b=null,
c=a.config.startDate;
b=a.config.serverTime?a.config.serverTime:parseInt(+newDate/1e3,10);
vard=c-1e3*60*a.config.minSignTime,
e=setInterval(function(){
varf=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('
$("#purchase_btn_2").html('
$("#countdown").html(f[0])},1e3)},
toBuy:function(){
vara=this;
a.goBuy();
varb=a.modeModals[a.config.mode];
$(b).find(".close").on("click",function(){
$(b).css("display","none"),
window.clearTimeout(a.timer),
a.timer=null})},
saleOut:function(){
vara={miphone:"#purchase_btn_2",mibox:"#purchase_btn_1"},
b={miphone:"http://t.hd.xiaomi.com/r/?_a=payment_check&_m=1",mibox:"http://m.xiaomi.com/index.html#ac=home&op=addcart&product_id=2505"},
c={miphone:"支付小米手机3",mibox:"支付小米电视"};
for(vardinthis.mode)
$.cookie(this.modeCookies[d])&&($(a[d]).html('
$(this.modeModals[d]).is(":visible")&&$(this.modeModals[d]).find(".close").click())},
localTime:function(){
vara=parseInt(+newDate/1e3,10);
returna
},
toProcess:function(a){
varb=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('
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(){
vara=this,
b={miphone:"购买小米手机3",mibox:"购买小米电视"},
c={miphone:"#purchase_btn_2",mibox:"#purchase_btn_1"};
for(vardina.mode)
$.cookie(a.modeCookies[d])||($(c[d]).html('
$(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;
varb=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="http://m.xiaomi.com/mshopapi/index.php/v1/authorize/sso?client_id=180100031013&callback="+encodeURIComponent(window.location.href)}})},
toBuyGo:function(a){
varb=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){
varc="http://t.hd.xiaomi.com/s/"+b.config[a].hdurl+"&_m=1";
window.setTimeout(function(){window.location.href=c},500)
}else{
vard="http://p.www.xiaomi.com/m/activities/open/"+b.config.hdurl[a];
window.setTimeout(function(){window.location.href=d},500)
}elseif(
b.config[a].hdstart===!1&&b.config[a].hdstop===!0){
vard="http://p.www.xiaomi.com/m/activities/open/"+b.config.hdurl[a];
window.setTimeout(function(){window.location.href=d},500)
}else$(b.modeModals[a]).find(".modal_btn").html('
b.toProcess(a)
})})}};

JavaScript字符串替换方法详解及常见问题解答 本文将探讨两种在JavaScript中替换字符串字符的方法:在JavaScript代码内部替换和在网页HTML内部替换。 在JavaScript代码内部替换字符串 最直接的方法是使用replace()方法: str = str.replace("find","replace"); 该方法仅替换第一个匹配项。要替换所有匹配项,需使用正则表达式并添加全局标志g: str = str.replace(/fi

本教程向您展示了如何将自定义的Google搜索API集成到您的博客或网站中,提供了比标准WordPress主题搜索功能更精致的搜索体验。 令人惊讶的是简单!您将能够将搜索限制为Y

本文系列在2017年中期进行了最新信息和新示例。 在此JSON示例中,我们将研究如何使用JSON格式将简单值存储在文件中。 使用键值对符号,我们可以存储任何类型的

增强您的代码演示:开发人员的10个语法荧光笔 在您的网站或博客上共享代码片段是开发人员的常见实践。 选择合适的语法荧光笔可以显着提高可读性和视觉吸引力。 t

因此,在这里,您准备好了解所有称为Ajax的东西。但是,到底是什么? AJAX一词是指用于创建动态,交互式Web内容的一系列宽松的技术。 Ajax一词,最初由Jesse J创造

利用轻松的网页布局:8个基本插件 jQuery大大简化了网页布局。 本文重点介绍了简化该过程的八个功能强大的JQuery插件,对于手动网站创建特别有用

本文介绍了关于JavaScript和JQuery模型视图控制器(MVC)框架的10多个教程的精选选择,非常适合在新的一年中提高您的网络开发技能。 这些教程涵盖了来自Foundatio的一系列主题

核心要点 JavaScript 中的 this 通常指代“拥有”该方法的对象,但具体取决于函数的调用方式。 没有当前对象时,this 指代全局对象。在 Web 浏览器中,它由 window 表示。 调用函数时,this 保持全局对象;但调用对象构造函数或其任何方法时,this 指代对象的实例。 可以使用 call()、apply() 和 bind() 等方法更改 this 的上下文。这些方法使用给定的 this 值和参数调用函数。 JavaScript 是一门优秀的编程语言。几年前,这句话可


热AI工具

Undresser.AI Undress
人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover
用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool
免费脱衣服图片

Clothoff.io
AI脱衣机

AI Hentai Generator
免费生成ai无尽的。

热门文章

热工具

螳螂BT
Mantis是一个易于部署的基于Web的缺陷跟踪工具,用于帮助产品缺陷跟踪。它需要PHP、MySQL和一个Web服务器。请查看我们的演示和托管服务。

PhpStorm Mac 版本
最新(2018.2.1 )专业的PHP集成开发工具

VSCode Windows 64位 下载
微软推出的免费、功能强大的一款IDE编辑器

记事本++7.3.1
好用且免费的代码编辑器

Atom编辑器mac版下载
最流行的的开源编辑器