$(function() { var FuckXiaoMi = { // 2135100018 红米手機 // 2130100011 行動電源 10400 // 2141300041 行動電源 5200 product: ['2141300041'], timer: null, speed: 500, count: 2, // 單品購買數量 delay: 4000, // 跳轉延遲 start: function() { var products = FuckXiaoMi.product; this.timer = window.setInterval(FuckXiaoMi.send, FuckXiaoMi.speed); }, send: function() { var products = FuckXiaoMi.product; var count = FuckXiaoMi.count; var delay = FuckXiaoMi.delay; $.each(products, function(index, product) { $.ajax({ url: "http://tp.hd.mi.com/hdget/tw?product=" + product + "&addcart=" + count + "&m=1", type: "get", dataType: "jsonp", jsonp: "callback", jsonpCallback: "hdcontrol", success: function(jsonObject) { var status = jsonObject.status[product]; var hdurl = status.hdurl; var hdstart = status.hdstart; var hdstop = status.hdstop; if ((hdstart = 'true') && (hdstop = 'false')) { if (status && hdurl != '') { window.clearInterval(FuckXiaoMi.timer); /*$.ajax({ url: 'http://buy.mi.com/tw/cart/add/' + product + '-0-2?source=bigtap&token=' + hdurl, dataType: 'jsonp' });*/ console.table('購物車網址 : ' + 'http://buy.mi.com/tw/cart/add/' + product + '-0-' + count + '?source=bigtap&token=' + hdurl); console.table(delay/1000 + '秒後跳轉 ...'); setTimeout(location.replace('http://buy.mi.com/tw/cart/add/' + product + '-0-2?source=bigtap&token=' + hdurl), delay); return false; } } var login = jsonObject.login; console.table("[login:" + login + ",hdstart:" + hdstart + ",hdstop:" + hdstop + ",hdurl:" + hdurl + "]"); }, error: function() { console.table("連線超時"); } }); }); } }; FuckXiaoMi.start(); });