码迷,mamicode.com
首页 > Web开发 > 详细

双11,自动领取优惠券 js 代码

时间:2015-10-16 06:17:13      阅读:255      评论:0      收藏:0      [点我收藏+]

标签:

http://www.zhihu.com/question/36426051/answer/67690322

本来我不熟悉 js,正好研究一下

 1 (function(window, document, undefined) {
 2     var interval = 800;
 3     var closeDelay = 200;
 4     var index = 0;
 5     var couponLinks;
 6     var getCoupon = function() {
 7         if (index >= couponLinks.length) {
 8             console.log("领取完毕");
 9             return;
10         }
11         var coponLink = couponLinks[index];
12         coponLink.click(); index++;
13         console.log("领取 第" + index + " 张");
14         setTimeout(getCoupon, interval);
15         setTimeout(function() {
16             var close = document.querySelector(‘.mui-dialog-close‘);
17             if (close != null)
18                 close.click();
19         }, closeDelay);
20     }
21     var _scrollTop = 0;
22     var _scrollStep = document.documentElement.clientHeight;
23     var _maxScrollTop = document.body.clientHeight - document.documentElement.clientHeight;
24     var autoScrollDown = setInterval(function() {
25         _scrollTop += _scrollStep;
26         if (_scrollTop > _maxScrollTop) {
27             clearInterval(autoScrollDown);
28             couponLinks = document.querySelectorAll(‘.mui-act-item-yhqbtn‘);
29             console.log("总共:" + couponLinks.length + "条张优惠券待领取…");
30             getCoupon();
31         } else {
32             document.body.scrollTop = _scrollTop;
33         }
34     }, 500);
35 }) (window, document);

搜一下关键的几个函数和变量,就很容易理解了。

document.querySelector
document.querySelectorAll
document.documentElement.clientHeight
document.body.clientHeight
document.body.scrollTop
setInterval
setTimeout

搞明白了这几含义,写个自动领券的代码还不是分分钟~

 

双11,自动领取优惠券 js 代码

标签:

原文地址:http://www.cnblogs.com/hangj/p/4884127.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!