天猫双十一领优惠券脚本
一直不会用$.Deferred(),正好赶上双十一就实验了一下,批量领券.
var allLiModule = new Array(); var curHref = 0; scrollTo(0, document.body.clientHeight); var scrollToTop = function () { var dtd = $.Deferred(); var scroolTimer = setInterval(function () { if (scrollY === 0) { dtd.resolve(); clearInterval(scroolTimer); return; } var newPosY = scrollY - 40; if (newPosY < 0) newPosY = 0; scrollTo(0, newPosY); }, 10); return dtd.promise(); } var clickReceive = function (elem) { scrollTo(0, elem.offsetTop); $(elem).find(".item-coupon-link")[0].click(); console.log(curHref); } var clickBtn = function () { var dtd = $.Deferred(); setTimeout(function () { $(".ui-button.ui-button-ok").click(); dtd.resolve(); }, (Math.random() * 2000) + 300); return dtd.promise(); } var whileClick = function () { if (curHref === allLiModule.length) { alert("完成"); return; } clickReceive(allLiModule[curHref]); $.when(clickBtn()) .done(function () { setTimeout(whileClick, (Math.random() * 2000) + 300); }); curHref += 1; } $.when(scrollToTop()) .done(function () { $(".mui-zebra-page .mui-act-items li").each(function () { var self = this; if ($(self).find(".item-coupon-link")[0]) { allLiModule.push(self); } }); }).done(function () { alert(allLiModule.length); }).done(function () { whileClick(); });
随便找一个天猫的分会场页面,就是能领好多优惠券的那种页面.放浏览器里执行脚本.ok