Greasy Fork

Greasy Fork is available in English.

淘宝众筹自动抢购

淘宝众筹自动下单代码,可以将即将放量的众筹项目显示为可点击,点击后即开始进入抢购,其中为提高抢购成功率,默认会将抢购的ID存到cookie中

当前为 2017-09-07 提交的版本,查看 最新版本

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         淘宝众筹自动抢购
// @namespace    http://tampermonkey.net/
// @version      2.1
// @description  淘宝众筹自动下单代码,可以将即将放量的众筹项目显示为可点击,点击后即开始进入抢购,其中为提高抢购成功率,默认会将抢购的ID存到cookie中
// @author       Nick Zhang
// @match        https://izhongchou.taobao.com/order/confirm_order.htm*
// @match        https://izhongchou.taobao.com/dreamdetail.htm*
// @match        http://err.taobao.com/error*.html
// @match        https://www.taobao.com/home/wait.php*
// @grant        none
// ==/UserScript==

(function() {
    var setCookie = function(name, value, opts){
        if(!name || !value){
            return;
        }
        var cookie = name + '=' + value;
        for(var key in opts){
            cookie +=';' + key + '=' + opts[key];
        }
        document.cookie = cookie;
    },
        getCookie = function(name){
            var result;
            try{
                document.cookie.split(' ').forEach(function(cookie){
                    cookie = cookie.replace(/\;$/,'').split('=');
                    if(cookie[0] == name){
                        result = cookie[1];
                    }
                });
            }catch(e){
            }
            return result;
        },
        getId = function(){
            var id = '';
            try{
                id = window.location.search.match(/itemId\=(\d{1,})/)[1];
            }catch(e){}
            if(!id){
                id = getCookie('tbzcid');
            }
            if(id){
                setCookie('tbzcid', id, {
                    domain : '.taobao.com',
                    path : '/'
                });
            }
            return id;
        },
        createEvent = function(eventName, ofsx, ofsy) {
            var evt = document.createEvent('MouseEvents');
            evt.initMouseEvent(
                eventName , true , false , null ,
                0 , 0 , 0 , ofsx, ofsy, false, false , false, false, 0, null
            );
            return evt;
        },
        moveCode = function(obj, box){
            var boxRect = box.getBoundingClientRect();
            var move = createEvent('mousemove', boxRect.left + obj.offsetLeft + box.clientWidth, boxRect.top + obj.offsetTop - 10),
                down = createEvent('mousedown', boxRect.left + obj.offsetLeft, boxRect.top + obj.offsetTop),
                up = createEvent('mouseup');
            obj.dispatchEvent(down);
            document.dispatchEvent(move);
            obj.dispatchEvent(up);
        };

    if(window.location.href.indexOf('https://izhongchou.taobao.com/dreamdetail.htm') < 0){
        var id = getId();
        //下单页面
        setTimeout(function(){
            var submit = document.querySelectorAll('#J_submitForm'),
                checkboxs = document.querySelectorAll('div.opt-anony input[type=checkbox]');
            if(submit.length && checkboxs.length){
                checkboxs = Array.prototype.slice.call(checkboxs);
                checkboxs.forEach(function(checkbox){
                    checkbox.checked = true;
                });
                var codeBox = document.querySelector('.nc_wrapper');
                codeObj = document.querySelector('.nc_iconfont');
                if(codeBox){
                    moveCode(codeObj, codeBox);
                    setTimeout(function(){
                        submit[0].click();
                    }, 1500);
                } else{
                    submit[0].click();
                }
            } else {
                setTimeout(function(){
                    if(!!id){
                        window.location.href = 'https://izhongchou.taobao.com/order/confirm_order.htm?itemId=' + id;
                    } else{
                        window.location.reload();
                    }
                },1000);
            }
        },1500);
    } else {
        //详情页面
        setTimeout(function(){
            if(document.querySelector('.reserve-btn') && document.querySelector('.reserve-btn').textContent == '筹款结束') return;
            var items = document.querySelectorAll('.repay');
            var hasFoundCommingItem = false;
            items = Array.prototype.slice.call(items);
            items.forEach(function(item){
                var id = '#'+item.getAttribute('id');
                if(document.querySelectorAll(id + ' .buy-num > em > span').length && document.querySelectorAll(id + ' .buy-num > em > span')[0].textContent > 0){
                    hasFoundCommingItem = true;
                    var link = document.querySelector(id + ' .repay-buy');
                    if(link.getAttribute('class').indexOf('repay-cannotbuy') > -1){
                        link.setAttribute('class', 'repay-buy');
                        link.innerText = '即将开始,点我开抢';
                        link.setAttribute('target','new');
                        link.setAttribute('href','https://izhongchou.taobao.com/order/confirm_order.htm?itemId=' + item.getAttribute('id').replace('repay-',''));
                    }
                }
            });
            if(!hasFoundCommingItem){
                console.warn('还没有发现即将开始抢购的众筹,即将刷新页面获取最新数据');
                setTimeout(function(){
                    window.location.reload();
                }, 2000);
            } else{
                console.info('已经找到即将开始的众筹项目,看页面点击吧');
            }
        },1000);
    }
})();