hdcontrol({"stime":1384914223,"d22a51":5,"status":{"miphone":{"hdstart":false,"hdstop":true,"hdurl":"","duration":null,"pmstart":false,"reg":true},"mibox":{"hdstart":false,"hdstop":true,"hdurl":"","duration":null,"pmstart":false,"reg":true},"mitv":{"hdstart":false,"hdstop":true,"hdurl":"","duration":null,"pmstart":false,"reg":true}}})
抢购成功的json
hdcontrol({
"stime": 1378180861,
"status": {
"allow": false,
"miphone": {
"hdstart": true,
"hdstop": false,
"hdurl": "?_a=20130903_september_first_weeks&_op=choose",
"duration": null,
"pmstart": false
},
"mibox":
{
"hdstart": true,
"hdstop": false,
"hdurl": "?_a=20130903_september_first_weeks&_op=choose",
"duration": null,
"pmstart": false
}
}
})
/*
* EnLei
* 2013-11-18
*/
function forNum(e) {
return e < 10 ? "0" + e: e
}
function countdown(e, t) {
var n = (new Date(t)).getTime() / 1e3,
r = n - e,
i = parseInt(r % 60),
s = parseInt(r / 60 % 60),
o = parseInt(r / 3600 % 24),
u = parseInt(r / 3600 / 24),
a = !0,
f = [i.toString(), s.toString(), o.toString()];
if (r <= 0) return ["00小时00分00秒", !0];
if (u > 0) {
window._timestr = u + "天" + forNum(f[2]) + "时" + forNum(f[1]) + "分" + forNum(f[0]) + "秒";
return [u + "<span>天</span>" + forNum(f[2]) + "<span>时</span>" + forNum(f[1]) + "<span>分</span>" + forNum(f[0]) + "<span>秒</span>", !1]
}
window._timestr = forNum(f[2]) + "时" + forNum(f[1]) + "分" + forNum(f[0]) + "秒";
return [forNum(f[2]) + "<span>时</span>" + forNum(f[1]) + "<span>分</span>" + forNum(f[0]) + "<span>秒</span>", !1]
}
function isApp() {
try {
if ( !! WE) return ! 0
} catch(e) {}
return ! 1
}
function WebEventTrigger(e, t) {
try {
if (WE && WE.trigger) {
typeof t != "string" && (t = JSON.stringify(t));
return WE.trigger(e, t)
}
} catch(n) {}
return ! 1
}
var qg = {
req: !0,
config: {
startDate: +(new Date("11/19/2013 12:00:00")),
loginDate: 7200,
ajax: {
hdinfo: {
timeout: 3e4,
url: "http://tc.hd.xiaomi.com/hdinfo"
},
hdget: {
timeout: 3e4,
url: "http://tc.hd.xiaomi.com/hdget"
}
},
url: {
login: "http://m.xiaomi.com/mshopapi/index.php/v1/authorize/sso?client_id=180100031013&callback=" + encodeURIComponent(window.location.href),
bbsurl: "http://bbs.xiaomi.cn/thread-8535476-1-1.html"
},
goods: {
miphone: {
name: "手机",
pay: "http://t.hd.xiaomi.com/r/?_a=payment_check&_m=1",
noyuyue: "http://p.www.xiaomi.com/m/opentip/phone/tip_NoRegister.html?_r=20131119&v=201310251734",
saledone: "http://p.www.xiaomi.com/m/opentip/phone/tip_SaledOverAll.html?_r=20131119&v=201310251734",
queryurl: "http://t.hd.xiaomi.com/r/?_a=20131105&_op=check&_m=1",
ck: "xm_pf_wl"
},
mibox: {
name: "盒子",
pay: "http://t.hd.xiaomi.com/r/?_a=payment_check_box&_m=1",
noyuyue: "http://p.www.xiaomi.com/m/opentip/box/tip_NoRegister.html?_r=20131119&v=201310251734",
saledone: "http://p.www.xiaomi.com/m/opentip/box/tip_SaledOverAll.html?_r=20131119&v=201310251734",
queryurl: "http://t.hd.xiaomi.com/r/?_a=20131105&_op=check&_m=1",
ck: "xm_pfb_wl"
},
mitv: {
name: "电视",
pay: "http://t.hd.xiaomi.com/r/?_a=payment_check_tv&_m=1",
noyuyue: "http://p.www.xiaomi.com/m/opentip/tv/tip_NoRegister.html?_r=20131119&v=123123",
saledone: "http://p.www.xiaomi.com/m/opentip/tv/tip_SaledOverAll.html?_r=20131119&v=123123",
queryurl: "http://t.hd.xiaomi.com/r/?_a=20131105_tv&_op=check&_m=1",
ck: "xm_pft_wl"
}
}
},
init: function() {
this.getInfo()
},
statu: {
user: {
isLogin: !1,
reg: {},
buy: {},
clearBuy: function() {
for (var e in qg.statu.user.buy) qg.statu.user.buy[e] = !1
}
},
hd: {
start: !1,
loginTime: !1,
end: {},
allEnd: !1
}
},
getInfo: function() {
var e = this;
$.ajax({
url: e.config.ajax.hdinfo.url,
dataType: "jsonp",
jsonpCallback: "hdinfo",
timeout: e.config.ajax.hdinfo.timeout,
beforeSend: function() {
e.ajax.hdinfo.load();
e.req = !1
},
error: function(t) {
if (e.ajax.notFound(t, !0)) return;
e.ajax.hdinfo.connect()
},
success: function(t) {
e.req = !0;
e.ajax.hdinfo.success(t)
},
complete: function() {}
})
},
getDate: function() {
var e = this;
$.ajax({
url: e.config.ajax.hdget.url,
dataType: "jsonp",
jsonpCallback: "hdcontrol",
timeout: e.config.ajax.hdget.timeout,
beforeSend: function() {
e.ajax.hdget.load();
e.req = !1
},
error: function(t) {
if (e.ajax.notFound(t, !1)) return;
e.ajax.hdget.connect()
},
success: function(t) {
e.req = !0;
e.ajax.hdget.success(t)
},
complete: function() {}
})
},
ajax: {
notFound: function(e, t) {
if (e.status == 404) {
qg.req = !0;
qg.statu.user.clearBuy();
handle.ajax.error.notFound(t);
return ! 0
}
return ! 1
},
hdget: {
load: function() {
qg.req && handle.ajax.hdget.load()
},
connect: function(e) {
e ? e = parseInt(e) * 1e3: e = 2e3;
setTimeout(function() {
qg.getDate()
},
e)
},
success: function(e) {
qg.getStatus.hd(e);
qg.process.hdget();
for (var t in qg.statu.user.buy) if (qg.statu.user.buy[t] == 1) {
if (qg.statu.hd.end[t]) {
qg.statu.user.buy[t] = !1;
handle.ajax.hdget.saledover(t);
return
}
if (e.status[t].hdurl !== "") {
qg.statu.user.buy[t] = !1;
handle.ajax.hdget.success(e.status[t].hdurl)
} else {
handle.ajax.hdget.reload(e.d22a51);
qg.ajax.hdget.repull(e.d22a51)
}
}
},
repull: function(e) {
qg.ajax.hdget.connect(e)
}
},
hdinfo: {
load: function() {
qg.req && handle.ajax.hdinfo.load()
},
connect: function() {
handle.ajax.error.timeout();
setTimeout(function() {
qg.getInfo()
},
2e3)
},
success: function(e) {
handle.ajax.hdinfo.success();
qg.config.currentDate = e.stime;
qg.getStatus.hd(e);
qg.getStatus.user(e);
qg.process.hdinfo()
}
}
},
getStatus: {
hd: function(e) {
var t = qg.config.startDate,
n = qg.config.currentDate * 1e3;
n >= t && (qg.statu.hd.start = !0);
for (var r in e.status) e.status[r].hdstop == 1 && e.status[r].hdstart == 0 ? qg.statu.hd.end[r] = !0 : qg.statu.hd.end[r] = !1
},
user: function(e) { ! $.cookie("userId") || (qg.statu.user.isLogin = !0);
for (var t in e.status) {
qg.statu.user.reg[t] = e.status[t].reg;
qg.statu.user.buy[t] = !1
}
},
checkEnd: function(e) {
qg.statu.hd.allEnd = !0;
for (var t in qg.statu.hd.end) qg.statu.hd.end[t] ? e(t) : qg.statu.hd.allEnd = !1
},
loginTime: function() {
var e = qg.config.startDate,
t = qg.config.currentDate * 1e3,
n = e - qg.config.loginDate * 1e3;
t >= n && (qg.statu.hd.loginTime = !0)
}
},
countDown: function() {
var e = this,
t = e.config.startDate,
n = e.config.currentDate,
r = t - e.config.loginDate * 1e3,
i = setInterval(function() {
var e = countdown(n, t);
if (e[1]) {
clearInterval(i);
qg.statu.hd.start = !0;
qg.process.hdinfo()
} else {
if (n * 1e3 == r) {
qg.statu.hd.loginTime = !0;
qg.process.hdinfo()
}
n += 1
}
handle.hdinfo.showTime(e[0])
},
1e3)
},
process: {
hdget: function() {
qg.getStatus.checkEnd(function(e) {
handle.end.one(e)
});
if (qg.statu.hd.allEnd) {
handle.end.all();
return
}
},
hdinfo: function() {
if (qg.statu.hd.start) {
handle.hdinfo.start();
qg.getStatus.checkEnd(function(e) {
handle.end.one(e)
});
if (qg.statu.hd.allEnd) {
handle.end.all();
return
}
if (!qg.statu.user.isLogin) {
handle.login.no();
return
}
for (var e in qg.statu.user.reg) qg.statu.user.reg[e] && !qg.statu.hd.end[e] ? handle.hdinfo.reg.bind(e) : !qg.statu.user.reg[e] && !qg.statu.hd.end[e] && handle.hdinfo.reg.none(e)
} else ! qg.statu.hd.start && !qg.statu.hd.loginTime && handle.hdinfo.countdown();
qg.statu.hd.loginTime && !qg.statu.hd.start && (isApp() || handle.hdinfo.login())
}
}
},
handle = {
dom: {
pop: $("#pop"),
mask: $("#mask"),
loading: $("#loading"),
time: $("#time"),
btn1: $("#btn1"),
btn2: $("#btn2"),
btn3: $("#btn3")
},
hdinfo: {
countdown: function() {
handle.hdinfo.showBtn.countdown();
qg.getStatus.loginTime();
qg.countDown()
},
start: function() {
handle.dom.time.remove();
var e = [];
for (var t in qg.config.goods) e.push('<a class="qgbtn" id="' + t + '" name="' + t + '" href="javascript:;">抢购' + qg.config.goods[t].name + "</a>");
handle.dom.btn1.html(e[0]);
handle.dom.btn2.html(e[1]);
handle.dom.btn3.html(e[2])
},
showTime: function(e) {
handle.dom.time.find("strong").html(e);
handle.dom.time.show().off("click").on("click",
function() {
window.location.reload()
})
},
showBtn: {
countdown: function() {
var e = '<a href="' + qg.config.goods.miphone.queryurl + '">查询手机/盒子资格</a>',
t = '<a href="' + qg.config.goods.mitv.queryurl + '">查询电视资格</a>',
n = '<a href="' + qg.config.url.bbsurl + '">活动详情</a>';
handle.dom.btn1.html(e);
handle.dom.btn2.html(t);
handle.dom.btn3.html(n)
}
},
reg: {
bind: function(e) {
var t = e;
$("#" + t).off("click").on("click",
function() {
qg.statu.user.clearBuy();
if ( !! qg.req) {
var e = $(this).attr("name");
qg.statu.user.buy[e] = !0;
qg.getDate()
}
return ! 1
})
},
none: function(e) {
var t = e,
n = qg.config.goods[e].noyuyue;
$("#" + t).off("click").on("click",
function() {
window.location.href = n;
return ! 1
})
}
},
login: function() {
var e = qg.config.url.login,
t = '<a href="' + e + '">提前登录</a>',
n = '<a href="javascript:;">已登录</a>';
qg.statu.user.isLogin ? handle.dom.btn3.html(n) : handle.dom.btn3.html(t)
}
},
ajax: {
error: {
timeout: function() {
$("#loading:visible") && handle.dom.loading.html("努力加载中...")
},
notFound: function(e) {
$("#loading:visible") && handle.dom.loading.hide();
handle.ajax.error.showNotFound();
e ? $("#notFound").find("#nbtn").off("click").on("click",
function() {
window.location.reload()
}) : $("#notFound").find("#nbtn").off("click").on("click",
function() {
handle.dom.mask.hide();
handle.dom.pop.hide()
})
},
showNotFound: function() {
handle.dom.mask.show();
handle.dom.pop.show().find(".pb").hide();
handle.dom.pop.find("#notFound").show()
}
},
hdinfo: {
load: function() {
handle.ajax.hdinfo.showLoad()
},
success: function() {
handle.ajax.hdinfo.hideLoad()
},
showLoad: function() {
handle.dom.mask.show();
handle.dom.loading.show()
},
hideLoad: function() {
if ($("#loading:visible")) {
handle.dom.mask.hide();
handle.dom.loading.hide().html("正在加载...")
}
}
},
hdget: {
load: function() {
handle.dom.mask.show();
handle.dom.pop.show().find(".pb").hide();
handle.dom.pop.find("#hdgetLoad").show()
},
reload: function(e) {
handle.dom.pop.find(".pb").hide();
handle.dom.pop.find("#hdgetReload").show().find("#t").html(e)
},
success: function(e) {
handle.dom.mask.hide();
handle.dom.pop.hide();
var e = "http://t.hd.xiaomi.com/s/" + e + "&_m=1";
window.location.href = e
},
saledover: function(e) {
var t = qg.config.goods[e].saledone;
handle.dom.mask.hide();
handle.dom.pop.hide();
window.location.href = t
}
},
setpay: function() {
if (!qg.statu.hd.start) return ! 1;
for (var e in qg.config.goods) ! $.cookie(qg.config.goods[e].ck) || handle.end.one(e)
}
},
end: {
all: function() {},
one: function(e) {
var t = qg.config.goods[e].name,
n = qg.config.goods[e].pay;
$("#" + e).html("支付" + t).off("click").on("click",
function() {
window.location.href = n
})
}
},
login: {
no: function() {
$(".qgbtn").off("click").on("click",
function() {
isApp() ? WebEventTrigger("login", null) : window.location.href = "http://m.xiaomi.com/mshopapi/index.php/v1/authorize/sso?client_id=180100031013&callback=" + encodeURIComponent(window.location.href)
})
}
}
};