Skip to content

Instantly share code, notes, and snippets.

@j-iNFINITE
Created September 6, 2016 06:36
Show Gist options
  • Save j-iNFINITE/3d0e57d4af1aa317447cc30f2719ac2a to your computer and use it in GitHub Desktop.
Save j-iNFINITE/3d0e57d4af1aa317447cc30f2719ac2a to your computer and use it in GitHub Desktop.
(function(window, document, undefined) {
var interval = 800;
var closeDelay = 200;
var index = 0;
var couponLinks;
var getCoupon = function() {
if (index >= couponLinks.length) {
console.log("领取完毕");
return;
}
var coponLink = couponLinks[index];
coponLink.click(); index++;
console.log("领取 第" + index + " 张");
setTimeout(getCoupon, interval);
setTimeout(function() {
var close = document.querySelector('.mui-dialog-close');
if (close != null) close.click();
}, closeDelay);
}
var _scrollTop = 0;
var _scrollStep = document.documentElement.clientHeight;
var _maxScrollTop = document.body.clientHeight - document.documentElement.clientHeight;
var autoScrollDown = setInterval(function() {
_scrollTop += _scrollStep;
if (_scrollTop > _maxScrollTop) {
clearInterval(autoScrollDown);
couponLinks = document.querySelectorAll('.j_ReceiveCoupon');
console.log("总共:" + couponLinks.length + "条张优惠券待领取...");
getCoupon();
} else {
document.body.scrollTop = _scrollTop;
}
}, 500);
}) (window, document);
来自 <https://www.v2ex.com/t/228164?p=1>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment