下面分析从第2行到第231行的,230行代码,这300行主要是关于程序的一些配置信息。
var randCount = parseInt(Math.random() * (0xa - 0x5 + 0x1) + 0x5),
//上来,先是一个随机数,就是从10到5的随机,让大家点击排队的时候,看到倒计时,不至于那么无聊,每次倒计时可以重试的时间可以是从5秒到10秒。
count = randCount, //这个随机数倒了下手,没意义。
ajaxCount = 0x0,
CONFIG = {
count: randCount, //倒数一个随机数的秒数,问题在于。。。如果打开页面的时候运气不好,roll个10,你就少比别人点击几次重试。。恶心啊。不过也是没啥意义
timer: {
status: 0x3e8, //1000
timeout: 0x1388, //5000,应该是5秒
getTimeout: 0x7530, //30000,30秒
server: 0x64 //100
//以上几个数,比较重要
},
proType: “”,
startDate: new Date(“11/19/2013 12:00:00”).getTime(),
preLogMin: 0x1e, //30
mIndex: "http://p.www.xiaomi.com/m/zt/open/index.html", //一张奇怪的网页,可以直接打开看看
srcs: {
hdget: “http://tc.hd.xiaomi.com/hdget?callback=hdcontrol&_=”, //抢购的url相关
hdinfo: “http://tc.hd.xiaomi.com/hdinfo?callback=hdinfo&_=” //抢购的一些信息,此处多数被调用
},
urls: {
phone: “http://t.hd.xiaomi.com/r/?_a=payment_check”,
tv: “http://t.hd.xiaomi.com/r/?_a=payment_check_tv”,
box: “ http://t.hd.xiaomi.com/r/?_a=payment_check_box”,
checkPhone:“http://t.hd.xiaomi.com/r/?_a=20131105&_op=check”, //日期有问题
checkTv: “http://t.hd.xiaomi.com/r/?_a=20131105_tv&_op=check”,
checkPhoneBuy: “http://t.hd.xiaomi.com/c/?_a=20131119_phone&_op=check”,
checkTvBuy: “http://t.hd.xiaomi.com/c/?_a=20131119_tv&_op=check”,
checkBoxBuy: “http://t.hd.xiaomi.com/c/?_a=20131119_box&_op=check”,
bookPhone: “http://t.hd.xiaomi.com/r/?_a=20131119&_op=book”,
bookTv: “http://t.hd.xiaomi.com/r/?_a=20131119_tv&_op=book",
bookBox: "http://t.hd.xiaomi.com/r/?_a=20131119&_op=book", //错了?
login: ”http://p.www.xiaomi.com/zt/xm_account/limitfacade.html?third=http%253A%252F%252Forder.xiaomi.com%252Flogin%252Fcallback%253Ffollowup%253Dhttp%25253A%25252F%25252Fp.www.xiaomi.com%25252Fopen%25252Findex.html%2526sign%253DYWY4NjlhMmExNzkzNGE5YTBjYjAzNzVjZTc1MmE5OTYwYmVlODc4NA%252C%252C%26sid%3Deshop&sid=eshop&callback=http%253A%252F%252Forder.xiaomi.com%252Flogin%252Fcallback%253Ffollowup%253Dhttp%25253A%25252F%25252Fp.www.xiaomi.com%25252Fopen%25252Findex.html%2526sign%253DYWY4NjlhMmExNzkzNGE5YTBjYjAzNzVjZTc1MmE5OTYwYmVlODc4NA%252C%252C&sign=9ZAFXvlDKGxSJhEBqKdOtQp633c%253D “ //session,里面有我的密码
},
isBook: {
phone: false,
tv: false,
box: false
},
cookies: {
app: ”orgin“,
status: ”xm_xt_prex“,
userid: ”userId“,
first: ”xm_firbut_hd“
} //cookie的信息
}; (function() {
m = { //模仿jquery的实现,或者就是直接copy了jquery的代码,用m代替$
arrelems: [],
ready: null,
doms: function() {
var f = this;
var c = false;
var d = [];
var e;
f.ready = function(g) {
if (c) {
g.call(document)
} else {
d.push(function() {
return g.call(this)
})
};
return this
};
var a = function() {
for (var g = 0x0; g < d.length; g++) {
d[g].apply(document)
};
d = null
};
var b = function(g) {
if (c) {
return
};
c = true;
a.call(window);
if (document.removeEventListener) {
document.removeEventListener("DOMContentLoaded", b, false)
} else {
if (document.attachEvent) {
document.detachEvent("onreadystatechange", b);
if (window == window.top) {
clearInterval(e);
e = null
}
}
}
};
if (document.addEventListener) {
document.addEventListener("DOMContentLoaded", b, false)
} else {
if (document.attachEvent) {
document.attachEvent("onreadystatechange",
function() {
if ((/loaded|complete/).test(document.readyState)) {
b()
}
});
if (window == window.top) {
e = setInterval(function() {
try {
c || document.documentElement.doScroll("left")
} catch(g) {
return
};
b()
},
0x5)
}
}
}
},
$: function() {
return typeof arguments[0x0] ==="string" ? document.getElementById(arguments[0x0]) : arguments[0x0]
},
cookie: function(d, e, b) {
if (arguments.length > 0x1 && String(e) !== "[object Object]") {
if (e === null || e === undefined) {
b.expires = -0x1
};
if (typeof b.expires === "number") {
var g = b.expires,
c = b.expires = new Date();
c.setDate(c.getDate() + g)
};
e = String(e);
return (document.cookie = [encodeURIComponent(d), "=", b.raw ? e: encodeURIComponent(e), b.expires ? "; expires=" + b.expires.toUTCString() : "", b.path ? "; path=" + b.path: "", b.domain ? "; domain=" + b.domain: "", b.secure ?" " : "; secure"].join(""))
};
b = e || {};
var a, f = b.raw ?
function(h) {
return h
}: decodeURIComponent;
return (a = new RegExp(" (?:^|; )" + encodeURIComponent(d) + "=([^;]*)").exec(document.cookie)) ? f(a[0x1]) : null
},
addEvent: (function() {
if (document.addEventListener) {
return function(c, b, a) {
c.addEventListener(b, a, false)
}
} else {
return function(c, b, a) {
c.attachEvent("on" + b,
function() {
return a.call(c, window.event)
})
}
}
})(),
randomDiff: function(c, f) {
var a = c,
b = f,
d = Math.random() * (b - a + 0x1) + a;
return parseInt(d)
},
getQueryString: function(a) {
var b = new RegExp("(^|&)" + a +"=([^&]*)(&|$)","i");
var c = window.location.search.substr(0x1).match(b);
if (c != null) {
return unescape(c[0x2])
};
return null
},
//以下是一个关键函数,参数c,d,b,b是一个布尔值,表示可以重试,c是请求的链接,d被赋值给a.id
creatJs: function(c, d, b) {
if (b === true) {
getStatus.boxy(false, ” -cache “); //不缓冲
getStatus.boxy(true, ”“)
};
var a = document.createElement( ” script “); //创建一个javascript块
requestTimer = setTimeout(function() {
if (b === true) {
getStatus.requestAgain()
}
},
CONFIG.timer.getTimeout); //30秒后,如果页面没有创建完毕,再次发送请求 一次。。
a.onload = a.onreadystatechange = function() {
if (!this.readyState || this.readyState === ”loaded“ || this.readyState === ”complete“) {
window.clearTimeout(requestTimer);
a.onload = a.onreadystatechange = null
//如果30秒内,页面创建完毕了,就不重复请求了
}
};
a.onerror = function() {
if (b === true) {
getStatus.boxy(false, ”“);
getStatus.boxy(true, ” -cache“)
};
window.clearTimeout(requestTimer)
};
a.src = c;
a.id = d;
if (m.$(d)) { //把之前可能存在的同id的javascript块,给删除掉
m.$(d).parentNode.removeChild(m.$(d))
};
document.getElementsByTagName(”head“)[0x0].appendChild(a) //然后javascript给放到页面的head部分
},
phone: function(b) {
b = b || ”http://m.xiaomi.com“;//处理手机客户端,小米商城app
if (m.cookie(CONFIG.cookies.app) === ”mapp“) { //可以仿造。
m.cookie(CONFIG.cookies.app, null, {
path: ”/“,
domain: ".xiaomi.com"
});
return
};
var a = navigator.userAgent;
if (a.indexOf("Android") > -0x1 || a.indexOf("iPhone") > -0x1 || a.indexOf(”iPod“) > -0x1 || a.indexOf(”Symbian“) > -0x1) {
location.href = b //滚去访问手机版网页
}
},
locationNext: function(a) { //下一个位置,用来跳转页面的函数
if (a == null || a == ”“) {
window.location.reload()
} else {
location.href = ” http://t.hd.xiaomi.com/s/“+ a
}
},
//下面是一个方便的cookie存储函数
cookieXM: function(b, a) {
m.cookie(b, a, {
path: ”/“,
domain: ”.xiaomi.com“,
expires: 0x1
})
},
init: function() {
var a = this;
a.doms()
}
};
m.init()
})();
完工。