zoukankan      html  css  js  c++  java
  • 抢书之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);
    复制代码
  • 相关阅读:
    PDF文件中的Form保存问题
    Understanding IP Fragmentation
    tcp ip guide IPsec IKE
    Windows安全事件日志中的事件编号与描述
    Cisco PIX fix up and Juniper firewall FTP ALG
    很好的IPSec介绍,详细解释了IKE协商的2个阶段的作用
    virtualbox 下运行Ubuntu 8.10的分辨率和guest additions的问题。
    Fixing the ‘Do you want to display nonsecure items’ message
    windows xp 开始菜单里面所有项目右键不起作用。
    HP backup and recovery manager
  • 原文地址:https://www.cnblogs.com/Leo_wl/p/2734485.html
Copyright © 2011-2022 走看看