Skip to content

Instantly share code, notes, and snippets.

@scott-ho
Last active May 8, 2018 02:29
Show Gist options
  • Save scott-ho/b5882b38e9767b8d1a3e8ca2efb298bb to your computer and use it in GitHub Desktop.
Save scott-ho/b5882b38e9767b8d1a3e8ca2efb298bb to your computer and use it in GitHub Desktop.
fuckxiaomi

使用方式:

  1. chrome 浏览器打开 如下链接 https://item.mi.com/product/10000085.html 或其他抢购链接
  2. 选中需要抢购的产品,记住,这一步非常重要
  3. 键盘点击 F12
  4. 在弹出的窗口 选中 console 选项卡 或者点击 键盘 ESC
  5. 在输入光标处 粘贴 下面文件的代码,点击 enter 键
(function test(startHour = 10) {
const timePoint = startHour
? new Date(`${new Date().toISOString().slice(0, 10)} ${startHour}:00`).getTime()
: new Date().getTime() + 5000
const gidSeletor = '#J_list .J_step:nth-child(2) .step-list .btn[class*="active"]'
hackMI()
main()
function tryBuy() {
var t = {
obj: ".xmAddShopCart",
modeType: "",
before: null,
callback: null,
overCallback: null,
beforeQueue: null,
storage: "000",
sourceVal: "bigtap"
};
MI.bigtap.init({
gid: $(gidSeletor).data().id,
modeType: t.modeType,
callback: t.callback,
obj: $('.xmAddShopCart'),
overCallback: t.overCallback,
beforeQueue: t.beforeQueue,
storage: t.storage,
sourceVal: t.sourceVal
})
}
function testIdRetrival() {
const testId = $(gidSeletor).data().id
console.log('The selected gid is: ', testId)
}
function main() {
let timesup = false
let timeleft = Math.floor((timePoint - Date.now()) / 1000)
testIdRetrival()
const interval = setInterval(function () {
var cur = Date.now()
if (cur >= timePoint) {
tryBuy()
timesup = true
}
if (timesup) {
clearInterval(interval)
} else {
let temp = Math.floor((timePoint - cur) / 1000)
if (temp < timeleft) {
timeleft = temp
console.log('time left ', timeleft, ' s')
}
}
}, 16)
}
function hackMI() {
let errorCount = 0
Object.assign(MI.bigtap, {
getHdget: function () {
var e = this
, t = 'cn' + e.config.gid
, n = MI.GLOBAL_CONFIG.damiaoSite + 'hdget/cn';
$.ajax({
type: 'GET',
url: n,
dataType: 'jsonp',
jsonp: 'jsonpcallback',
data: {
source: e.config.sourceVal,
product: e.config.gid,
addcart: 1,
m: 1,
fk: e.config.modeVal,
tsort: e.config.modeTime,
storage: e.config.storage,
cstr1: e.config.jsSignResult.cstr1,
cstr2: e.config.jsSignResult.cstr2,
event: e.config.jsSignResult.ev,
r: e.config.jsSignResult.r,
b: e.config.jsSignResult.b,
salt: e.config.salt,
ans: e.config.mi6Sign
},
jsonpCallback: t,
timeout: 3e4,
error: function (t, i, r) {
if (errorCount < 50 ) {
console.log(e.inTheQueue)
e.inTheQueue || e.startQueue()
e.getHdgetTimer = setTimeout(function () {
e.getHdget()
}, 16)
}
errorCount ++
console.log('errors: ', errorCount)
},
success: function (t) {
var n = t.status
, i = n[e.config.gid].hdurl
, isStop = !n[e.config.gid].hdstart && n[e.config.gid].hdstop;
if (e.inTheQueue) {
if (!isStop) {
e.getHdgetTimer && clearTimeout(e.getHdgetTimer)
if (i) {
e.getShopCart(i)
} else {
e.inTheQueue || e.startQueue()
e.getHdgetTimer = setTimeout(function () {
e.getHdget()
}, 50)
}
} else {
alert('活动已结束')
e.stopQueue()
}
}
}
})
}
})
}
})()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment