好得很程序员自学网

<tfoot draggable='sEl'></tfoot>

抢书之JS版

抢书之JS版

无疑汤姆大叔送书是今天的热点,此贴一出立即在园子里面引起了轩然大波,书啊,免费,30本立即让大家红了眼啊,人气那叫一个排山倒海,大有要盖园子里最高楼的豪情啦,还等什么,赶快加入抢书热潮吧

  咱是程序员,抢书也得科学,自第一次抢书失败后,我便写了一个用户脚本,代码很简单,咱就让悬念停在提交延时那一块和谁对博客园服务器时间测试得更准确,行,开工,下面我粘一下代码,是一段用户脚本,存为GrabTheBook.user.js,拖到google浏览器,然后刷新就可以了,最后说一句:大叔莫怪!

 //   ==UserScript==  
//   @name         Grab The Book  
//   @author       Xian Hong  
//   @namespace    http://www.cnblogs.com/xianhong/  
//   @description  抢汤姆大叔的书咯  
//   @include      http://www.cnblogs.com/TomXu/*  
//   ==/UserScript== 
 function   withjQuery(callback, safe) {
      if  ( typeof  (jQuery) == "undefined" ) {
          var  script = document.createElement("script" );
        script.type  = "text/javascript" ;
        script.src  = "https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js" ;

          if   (safe) {
              var  cb = document.createElement("script" );
            cb.type  = "text/javascript" ;
            cb.textContent  = "jQuery.noConflict();(" + callback.toString() + ")(jQuery);" ;
            script.addEventListener( 'load',  function   () {
                document.head.appendChild(cb);
            });
        }
          else   {
              var  dollar =  undefined;
              if  ( typeof  ($) != "undefined") dollar =  $;
            script.addEventListener( 'load',  function   () {
                jQuery.noConflict();
                $  =  dollar;
                callback(jQuery);
            });
        }
        document.head.appendChild(script);
    }   else   {
        callback(jQuery);
    }
};

withjQuery(  function   ($) {
      var  div = $("<div>", { html: '.', style: 'position: fixed;top: 10px;left: 10px;display: block;-webkit-text-size-adjust: none;font-size: 15px;color: red; 50px;height: 50px;'  }).appendTo($(document.body));
      var  getCurTime =  function   () {
          var  curTime =  new   Date();
          var  hour =  curTime.getHours();
          var  minutes =  curTime.getMinutes();
          var  second =  curTime.getSeconds();
        div.html(hour  + ':' + minutes + ":" +  curTime.getSeconds());
          return   {
            hour: hour,
            minutes: minutes,
            second: second
        };
    };

      var  grabTheBook =  function   () {
        $( "#tbCommentBody").html("又来抢书咯,老天保佑!" );
        $( "#btn_comment_submit" ).click();
    };

      var  templateFun =  function   (h, m, s) {
          var  breakFlag =  false  ; //大叔说重复了就没有
          var  f =  function   () {
              var  curTime =  getCurTime();
              if  (!breakFlag && curTime.hour == h && curTime.minutes == m && curTime.second >=  s) {
                breakFlag  =  true  ;
                grabTheBook();
            }
              else   {
                setTimeout(f,  10 );
            }
        };
          return   f;
    };

    div.click(  function   () {
        grabTheBook();
    });
    
    templateFun( 10, 0, 2 )();  //需要微调的地方,最后一个参数是秒数,下面几行一样
    templateFun( 12, 0, 2 )();
    templateFun( 14, 0, 2 )();
    templateFun( 16, 0, 2 )();
    templateFun( 18, 0, 2 )();
    templateFun( 20, 0, 2 )();
},   true );

作者: Leo_wl

    

出处: http://www.cnblogs.com/Leo_wl/

    

本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。

版权信息

查看更多关于抢书之JS版的详细内容...

  阅读:43次