淘宝、天猫、聚划算、京东、苏宁抢购助手v2

淘宝、天猫、聚划算、京东、苏宁自动抢购工具,支持淘宝、天猫、聚划算、京东、苏宁易购的商品页面抢购、购物车抢购,在非抢购页面支持淘宝、天猫、京东、苏宁易购隐藏优惠券领取及历史价格查看。

Versione datata 15/02/2020. Vedi la nuova versione l'ultima versione.

// ==UserScript==
// @name         淘宝、天猫、聚划算、京东、苏宁抢购助手v2
// @namespace    Aice.Fu_gwTools
// @version      0.1.23
// @description  淘宝、天猫、聚划算、京东、苏宁自动抢购工具,支持淘宝、天猫、聚划算、京东、苏宁易购的商品页面抢购、购物车抢购,在非抢购页面支持淘宝、天猫、京东、苏宁易购隐藏优惠券领取及历史价格查看。
// @include     /http(?:s|)://(?:detail|item)\.(?:taobao|tmall)\.(?:[^./]+)/item.htm/
// @include     https://chaoshi.tmall.com/*
// @include     https://chaoshi.detail.tmall.com/*
// @include     https://detail.tmall.hk/*
// @include     https://buy.tmall.com/order/*
// @include     https://buy.taobao.com/*
// @include     https://cart.tmall.com/*
// @include     https://cart.taobao.com/*
// @include     https://cart.jd.com/*
// @include     */item.jd.com/*
// @include     *//item.jd.hk/*
// @include     https://trade.jd.com/shopping/order/*
// @include     https://wqdeal.jd.com*
// @include     https://wqs.jd.com*
// @include     */product.suning.com/*
// @include     https://shopping.suning.com/cart.do*
// @include     https://shopping.suning.com/order.do*
// @require     https://code.jquery.com/jquery-latest.js
// @grant       GM_xmlhttpRequest
// @grant       GM_setValue
// @grant       GM_getValue
// @grant       unsafeWindow
// @connect     gwdang.com
// @connect     ubja.vip
// @connect     alicdn.com
// @author      Aice.Fu

// ==/UserScript==

(function() {
    'use strict';
    var myCon = '<dl><dt>&nbsp;</dt></dl><dd><a style="padding:5px 28px;background:blue;color:#fff;cursor:pointer;font-size:1.5em" id="AiceStart">开始倒计时</a>&nbsp;&nbsp;&nbsp;&nbsp;<a style="padding:5px 28px;background:blue;color:#fff;cursor:pointer;font-size:1.5em" id="AicePrice">历史价格</a>&nbsp;&nbsp;<input id="QgMode" type="checkbox" />强制开启抢购模式&nbsp;&nbsp;<dd></dl><dl id="AicePm"><dd>开始时间&nbsp;&nbsp;<input id="AiceStartTime" style="width:180px;"/>&nbsp;&nbsp;提前&nbsp;&nbsp;<input type="number" id="AiceBeforeTime" style="width:35px;" value="100"/>ms</dd><dd> &nbsp;&nbsp;</dd><dd> <input id="AiceOsm" type="checkbox">自动下单</dd></dl><dl>更多优惠,请关注微信小程序</dl><dl><dt><image src="https://xcx.ubja.vip/app/barcode.jpg"><iframe id="fname" src="https://xcx.ubja.vip/myweb/tg.html" width="0" height="0" scrolling="no" /></dt></dl><dd></dl>';
    var myConSN = '<dl><dt>&nbsp;</dt></dl><dd><a style="padding:5px 28px;background:blue;color:#fff;cursor:pointer;font-size:1.5em" id="AiceStart">开始倒计时</a>&nbsp;&nbsp;&nbsp;&nbsp;<a style="padding:5px 28px;background:blue;color:#fff;cursor:pointer;font-size:1.5em" id="AicePrice">历史价格</a>&nbsp;&nbsp;<input id="QgMode" type="checkbox" />强制开启抢购模式&nbsp;&nbsp;</dd><dl><dt>&nbsp;</dt></dl><dd><dl id="AicePm">开始时间&nbsp;&nbsp;<input id="AiceStartTime" style="width:180px;"/>&nbsp;&nbsp;提前&nbsp;&nbsp;<input type="number" id="AiceBeforeTime" style="width:35px;" value="100"/>ms&nbsp;&nbsp;<input id="AiceOsm" type="checkbox">自动下单</dl><dl>更多优惠,请关注微信小程序</dl><dl><image src="https://xcx.ubja.vip/app/barcode.jpg"><iframe id="fname" src="https://xcx.ubja.vip/myweb/tg.html" width="0" height="0" scrolling="no" /></dl><dd></dl>';
    var myConJD = '<dd>&nbsp;&nbsp;</dd><dl><dt>&nbsp;</dt></dl><dl><dd>&nbsp;</dt></dd></dl><dd><a style="padding:5px 28px;background:blue;color:#fff;cursor:pointer;font-size:1.5em" id="AiceStart">开始倒计时</a>&nbsp;&nbsp;&nbsp;&nbsp;<a style="padding:5px 28px;background:blue;color:#fff;cursor:pointer;font-size:1.5em" id="AicePrice">历史价格</a>&nbsp;&nbsp;<input id="QgMode" type="checkbox" />强制开启抢购模式&nbsp;&nbsp<dd></dl><dl id="AicePm"><dd>开始时间&nbsp;&nbsp;<input id="AiceStartTime" style="width:180px;"/>&nbsp;&nbsp;提前&nbsp;&nbsp;<input type="number" id="AiceBeforeTime" style="width:35px;" value="100"/>ms</dd><dd> &nbsp;&nbsp;</dd><dd> <input id="AiceOsm" type="checkbox" checked="checked" style="display: none"></dd></dl><dl><dt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;更多优惠,请关注微信小程序</dl></dt><dl><dt><image src="https://xcx.ubja.vip/app/barcode.jpg"><iframe id="fname" src="https://xcx.ubja.vip/myweb/tg.html" width="0" height="0" scrolling="no" /></dt></dl><dd></dl>';
    var myConJDMb = '<dd>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span><a target="_blank" style="color: #2272c8;font-size: 1em;font-weight: bold;">购物助手 By Aice.Fu</a></span>&nbsp;&nbsp;&nbsp;&nbsp;<a style="padding:3px 28px;background:blue;color:#fff;cursor:pointer;font-size:1em" id="AiceStart">开始倒计时</a><dd>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;开始时间&nbsp;&nbsp;&nbsp;&nbsp;<input id="AiceStartTime" style="width:140px;"/>&nbsp;&nbsp;&nbsp;&nbsp;提前<input type="number" id="AiceBeforeTime" style="width:35px;" value="100"/>ms  &nbsp;&nbsp;&nbsp;&nbsp;<input id="AiceOsm" type="hidden" ><input id="AiceWx" type="radio" checked="checked" value="" />微信支付<input id="AiceJd" type="radio" value="" />京东支付</dd></dl>';
    var myConJDCart = '<dd><span><a target="_blank" style="color: #2272c8;font-size: 1em;font-weight: bold;">购物助手 By Aice.Fu</a></span>&nbsp;&nbsp;&nbsp;&nbsp;<a style="padding:3px 28px;background:blue;color:#fff;cursor:pointer;font-size:1em" id="AiceStart">开始倒计时</a><dd>开始时间&nbsp;&nbsp;&nbsp;&nbsp;<input id="AiceStartTime" style="width:140px;"/>&nbsp;&nbsp;&nbsp;&nbsp;提前<input type="number" id="AiceBeforeTime" style="width:35px;" value="100"/>ms  &nbsp;&nbsp;&nbsp;&nbsp;<dt><dd><input id="AiceOsm" type="checkbox" />自动下单&nbsp;&nbsp;<input id="AiceMqmode" type="checkbox" />盲抢模式&nbsp;&nbsp;提前<input type="number" id="AiceMqmodeTime" style="width:35px" value="3"/>s 刷新</dd></dt></dd></dl>';
    var myConCart = '<dd><span><a target="_blank" style="color: #2272c8;font-size: 1em;font-weight: bold;">购物助手 By Aice.Fu</a></span>&nbsp;&nbsp;&nbsp;&nbsp;<a style="padding:3px 28px;background:blue;color:#fff;cursor:pointer;font-size:1em" id="AiceStart">开始倒计时</a><dd>开始时间&nbsp;&nbsp;&nbsp;&nbsp;<input id="AiceStartTime" style="width:140px;"/>&nbsp;&nbsp;&nbsp;&nbsp;提前<input type="number" id="AiceBeforeTime" style="width:35px;" value="100"/>ms  &nbsp;&nbsp;&nbsp;&nbsp;<input id="AiceOsm" type="checkbox" />自动下单&nbsp;&nbsp;<input id="AiceMqmode" type="checkbox" />盲抢模式&nbsp;&nbsp;提前<input type="number" id="AiceMqmodeTime" style="width:35px" value="3"/>s 刷新</dd></dl>';
    var ifLj = null;
    var frmId = 0;
    var btnBuy = null;
    var realTime;
    var starttime;
    var endtime;
    var initsdtime_int = 0;//第一次获得的服务器时间
    var thissdtime_int;
    var d8;//抢购时间
    var cyce = 100; // 多少毫秒点击一次
    var bwtime = 100;//前置时间
    var gostart = 0;
    var btnCart= null;
    var ifYhq = 0;
    var chk = 1;
    var goodsId = null;
    var sjid = null ;
    var allck = null;//购物车全选
    var ifRef = 0; //是否刷新
    var mqBfTim = 3;//盲抢提前刷新时间
    var yhqid = "771280092";
    //历史价格提交参数
    var pdata =null;
    var pbeginTime=null;
    var picdata =null;
    //Loading
    var _PageHeight = document.documentElement.clientHeight,
        _PageWidth = document.documentElement.clientWidth;
    var _LoadingTop = _PageHeight > 61 ? (_PageHeight - 61) / 2 : 0,
        _LoadingLeft = _PageWidth > 215 ? (_PageWidth - 215) / 2 : 0;
    var _LoadingHtml = '<div id="loadingDiv" style="position:absolute;left:0;width:100%;height:' + _PageHeight + 'px;top:0;background:#f3f8ff;opacity:1;filter:alpha(opacity=80);z-index:10000;"><div style="position: absolute; cursor1: wait; left: ' + _LoadingLeft + 'px; top:' + _LoadingTop + 'px; width: auto; height: 57px; line-height: 57px; padding-left: 50px; padding-right: 5px; background: #fff url(Image/loading.gif) no-repeat scroll 5px 10px; border: 2px solid #95B8E7; color: #696969; font-family:\'Microsoft YaHei\';">页面加载中,请等待...</div></div>';const orgUrl = "https://xcx.ubja.vip/app/LKT/index.php?module=api&software_name=3&edition=1.0&action=exUrl";
    var froUrl = GM_getValue('locUrl');
    froUrl = froUrl==null?"":froUrl;
    var mqMd = GM_getValue('mqmd');
    ifRef = GM_getValue("ref");
    if(ifRef==1 | ifRef == null){
        GM_setValue("ref",0);
    }
    if(window.location.origin == "https://detail.tmall.com" || window.location.origin == "https://chaoshi.detail.tmall.com" || window.location.origin == "https://detail.tmall.hk"){
        var fdiv = getTargetByTAV('div','class','tb-sku');//'tb-action tm-clear');
        fdiv.id='J_Dtl';
        $('#J_Dtl').append(myCon);
        ifLj = getTargetByTAV('div','class','tb-btn-wait');
        btnBuy =getTargetById('J_LinkBuy');
        goodsId=/(?:&|\?)id=(\d+)/.exec(window.location.href)[1] ;
        if ((window.location.href.indexOf('mm_'+yhqid)==-1)&&(window.location.href!=froUrl)) {
            getYhqurl(goodsId,"",3);
        }
        mqMd = 0;
        frmId = 1;
    }
    if(window.location.origin == "https://item.taobao.com"){
        $('#J_isku').append(myCon);
        ifLj = getTargetByTAV('div','class','tb-btn-wait');
        btnBuy =getTargetByTAV('a','class','J_LinkBuy');
        goodsId=/(?:&|\?)id=(\d+)/.exec(window.location.href)[1] ;
        if ((window.location.href.indexOf('mm_'+yhqid)==-1)&&(window.location.href!=froUrl)) {
            getYhqurl(goodsId,"",3);
        }
        mqMd = 0;
        frmId = 2;
    }

    if(window.location.origin == "https://cart.taobao.com"){
        $('#J_Search').append(myConCart);
        frmId = 3;
    }

    if(window.location.origin == "https://cart.tmall.com"){
        $('#mallSearch').append(myConCart);
        frmId = 4;
    }

    if(window.location.origin == "https://item.jd.com"||window.location.origin == "https://item.jd.hk"){
        $('#choose-btns').append(myConJD);
        goodsId= /(\d+)\.html/.exec(window.location.href)[1] ;
        var purl = /item\.jd\.(?:[^./]+)\/(\d+)\.html/.exec(window.location.href)
        if (purl != null && (window.location.href.indexOf('?')==-1)&&(window.location.href!=froUrl)) {
            getYhqurl(goodsId,"",2);
        }
        mqMd = 0;
        frmId = 5;
    }

    if(window.location.origin == "https://cart.jd.com"){
        var Search = getTargetByTAV('div','class','w w1 header clearfix');
        Search.id = "AiceSearch"
        $('#AiceSearch').append(myConJDCart);
        frmId = 6;
    }

    if(window.location.origin == "https://product.suning.com"){
        goodsId= /(\d+)\.html/.exec(window.location.href)[1];
        sjid =  /(\d+)/.exec(window.location.href)[1];
         if ((window.location.href.indexOf('utm_source=union')==-1)&&window.location.href!=froUrl) {
            getYhqurl(goodsId,sjid,4);
        }
        var snDiv = getTargetByTAV('div','class','mainbtns clearfix');
        snDiv.id = "AiceDiv"
        $('#AiceDiv').append(myConSN);
        btnBuy =getTargetById('buyNowAddCart');
        mqMd = 0;
        frmId = 7;
    }

    if(window.location.origin == "https://shopping.suning.com" && window.location.href.indexOf('cart.do')!=-1 ){
        var SearchSn = getTargetByTAV('div','class','cart-search-box');
        SearchSn.id = "AiceSearch"
        $('#AiceSearch').append(myConCart);
        frmId = 8;
    }

    if(window.location.origin == "https://wqdeal.jd.com"){
        var SearchJdMb = getTargetByTAV('div','class','topbar');
        SearchJdMb.id = "AiceSearch"
        $('#AiceSearch').append(myConJDMb);
        mqMd = 0;
        frmId = 9;
    }

    if(window.location.origin == "https://wqs.jd.com"){
        mqMd = 0;
        frmId = 10;
    }

    var gtime ="2019-10-25 21:22:10.0";//抢拍时间
    gtime = gtime.substring(0,19);
    gtime = gtime.replace(/-/g,'/');
    var timestamp = new Date(gtime).getTime();
    var tp = getCookie("ft_qgd");
    var cDt = new Date();
    if (tp==null){
        setCookie("ft_qgd",timestamp);
        cDt.setTime(timestamp);
    }else{
        cDt.setTime(tp);
    }

    chk = GM_getValue("AutoSubOdr");

    if(frmId!=0){

        if (chk!=null){
            if (chk==0){
                document.getElementById('AiceOsm').checked=false;
            }else{
                document.getElementById('AiceOsm').checked=true;
            }
        }

        if(frmId==1|frmId==2|frmId==5|frmId==7){
            var QgMode = document.getElementById('QgMode');
            QgMode.addEventListener('click', function() {
                if(QgMode.checked==0){
                    $('#AiceStart').prop('lastChild').nodeValue="优惠券";
                    $('#AicePm').hide();
                    ifYhq=1;
                }else{
                    if(frmId==5){
                        //console.log("https://wqs.jd.com/order/s_confirm_miao.shtml?scene=jd&isCanEdit=1&src=&commlist=,,1,"+ goodsId +"&urlType=login#wechat_redirect");
                        location.replace("https://wqs.jd.com/order/s_confirm_miao.shtml?scene=jd&isCanEdit=1&src=&commlist=,,1,"+ goodsId +"&urlType=login#wechat_redirect");
                    }
                    gostart = 0;
                    $('#AiceStart').prop('lastChild').nodeValue="开始倒计时";
                    $('#AicePm').show();
                    ifYhq=0;
                }
            });
        }

        if(frmId==3|frmId==4|frmId==6|frmId==8){

            if(mqMd!=null){
                if (mqMd==0){
                    document.getElementById('AiceMqmode').checked=false;
                }else{
                    document.getElementById('AiceMqmode').checked=true;
                    mqMd = 1;
                }
            }

            var AiceMqmode = document.getElementById('AiceMqmode');
            AiceMqmode.addEventListener('click', function() {
                GM_setValue('mqmd',AiceMqmode.checked?1:0);
                AiceMqmode.checked?mqMd=1:mqMd=0;
            });

            mqBfTim = document.getElementById('AiceMqmodeTime').value;
        }

        bwtime = document.getElementById('AiceBeforeTime').value;


        var js = document.getElementById('AiceStartTime');
        js.value = dateFormat("YYYY-mm-dd HH:MM:SS", cDt);
        console.log(js.value);

        var tj = document.getElementById('AiceStart');
        tj.addEventListener('click', function() {
            gtime = document.getElementById('AiceStartTime').value ;
            gtime = gtime.substring(0,19);
            gtime = gtime.replace(/-/g,'/');
            var timestamp1 = new Date(gtime).getTime();
            setCookie("ft_qgd",timestamp1);
            //location.replace(location.href);
            if (ifYhq==1){
                //优惠券点击事件
                //alert("暂时无法使用该功能!");
                var frId =0;
                if (frmId==1 || frmId ==2){
                    frId =3;
                }
                if(frmId==5){
                    frId =2;
                }
                if(frmId==7){
                    frId =4;
                }
                var exUrl = orgUrl + "&m=GMurl&goodsid="+ goodsId +"&sjid="+ sjid +"&fromid="+frId;
                //console.log(exUrl);
                GM_xmlhttpRequest({
                    url: exUrl,
                    method: 'GET',
                    timeout: 10000,
                    headers: {
                        'Content-Type': 'application/json',
                        'Accept': 'application/json',
                        'Cache-Control': 'public'
                    },
                    onload: function(res)
                    {
                        try{
                            const json = JSON.parse(res.responseText)
                            if (json.code==100){
                                var exurl=json.msg.exurl;
                                if (frmId==5){
                                    var yhqurl= document.getElementById("fname").contentWindow.postMessage({a: exurl}, '*');
                                }else{
                                    window.location.href=exurl;
                                }
                            }else{
                                alert("该商品暂无优惠券!");
                            }
                        }catch(e){
                            alert("该商品暂无优惠券!");
                        }

                    }
                });


            }else{
                 GM_setValue("ref",0);
                if(frmId==3|frmId==4|frmId==6|frmId==8){
                  mqBfTim = document.getElementById('AiceMqmodeTime').value;
                }
                if(frmId==9){
                    var AiceZf = document.getElementById('AiceJd');
                    if (AiceZf==1){
                        btnBuy =getTargetByTAV('a','class','mod_btn bg_jd');
                    }else{
                        btnBuy =getTargetByTAV('a','class','mod_btn bg_wx');
                    }
                }
                if (gostart==0)
                {
                    gostart = 1;
                    ifRef = 0;
                    $('#AiceStart').prop('lastChild').nodeValue="正在倒计时";
                }else
                {
                    gostart = 0;
                    $('#AiceStart').prop('lastChild').nodeValue="开始倒计时";
                }
                syncTime();
            }

        });

        var AutoOsm = document.getElementById('AiceOsm');
        AutoOsm.addEventListener('click', function() {
            GM_setValue("AutoSubOdr",AutoOsm.checked?1:0);
            AutoOsm.checked?chk=1:chk=0;
        });


        var btnPrice = document.getElementById('AicePrice');
        if (btnPrice !== null && typeof(btnPrice) === 'object'){
            btnPrice.addEventListener('click', function() {
                //历史价格点击事件
                pdata = null;
                pbeginTime = null;
                picdata = null;
                var url = location.href;
                var gwdUrl = "https://browser.gwdang.com/extension/price_towards?url=" + encodeURIComponent(url)
                GM_xmlhttpRequest({
                    url: gwdUrl,
                    method: 'GET',
                    timeout: 10000,
                    headers: {
                        'Content-Type': 'application/json',
                        'Accept': 'application/json',
                        'Cache-Control': 'public'
                    },
                    onload: function(res)
                    {
                        //loadingMask.parentNode.removeChild(mask);
                        const json = JSON.parse(res.responseText)
                        if (json.is_ban == null){
                            //console.log(json);
                            var allHide="";
                            var yearHide="";
                            var monthHide="";
                            if (json.store[0].all_line == null) {
                                allHide="style='display: none;'";
                            }
                            if (json.store[0].year_line == null) {
                                yearHide="style='display: none;'";
                            }
                            if (json.store[0].month_line == null) {
                                monthHide="style='display: none;'";
                            }
                            var ddata;
                            if (json.store.length > 1) {
                                ddata = json.store[1].all_line;
                            }

                            pdata = json.store[0].all_line;
                            pbeginTime = json.store[0].all_line_begin_time;
                            picdata = ddata;

                            var hml = "<div   style='margin-left:50px;margin-top:20px;display: block;'><a class='active-plot type-plot' "+allHide+" id='plotAll'>全部</a><a class='type-plot' "+ yearHide +" id='plotYear'>年线</a><a class='type-plot' "+monthHide+" id='plotMonth'>月线</a>";
                            hml= hml + "<div id='hisprice' style='width: 720px;height:350px;margin: 0;padding: 0'></div>";
                            opWind('','0','历史价格',hisPriceShow(hml));
                        }else{
                            //console.log(json.action.to);
                            opWind(json.action.to,'1','请验证后刷新页面!','');
                        }
                    }
                });

            });

        }
    }



    function hisPriceShow(sBody){

        var priceHtml=
            `
<html>
<head>
<meta charset="gbk" />
<meta name="renderer" content="webkit"/>
<meta http-equiv="X-UA-Compatible" content="IE=Edge"/>
</head>
<TITLE>历史价格</TITLE>
<script src="https://cdnjs.cloudflare.com/ajax/libs/echarts/4.3.0/echarts.min.js"></script>
<BODY BGCOLOR=#ffffff>
${sBody}
</BODY>
<script>
var pChart = echarts.init(document.getElementById('hisprice'));
showPrice();
function showPrice() {
var data =[${pdata}];
var beginTime =${pbeginTime};
var picdata =[${picdata}];
var dt = [];
for (var i = 0; i < data.length; i++) {
var d = new Date(beginTime);
d.setDate(d.getDate() + i);
dt.push(d.toLocaleDateString());
}

// 指定图表的配置项和数据
var option = {

tooltip: {
enterable: true,
trigger: 'axis',
formatter: function (params) {

return params[0].axisValue + "<br/>" + params[0].data;
},
axisPointer: {
animation: false
}
},
legend: {
data: ['页面价', '到手价'],
selected: {
'页面价': true,
'到手价': true

}

},
xAxis: {
data: dt,
splitArea: { show: false },
boundaryGap: false,
splitLine: {
show: true,

},
axisLabel: {

interval: parseInt((data.length) / 10),
formatter: function (value) {

return value.substring(5);
}
},
},
yAxis: {
splitArea: { show: false },
splitLine: {
show: true,

}
},
series: [{
name: '页面价',
type: 'line',
data: data,
showSymbol: false,
hoverAnimation: false,
markPoint: {
symbol: 'pin',

data: [
{ type: 'max', name: '最大值' },
{ type: 'min', name: '最小值' }
]
},
markLine: {
data: [
{ type: 'average', name: '平均值' }
]
}
},
{
name: '到手价',
type: 'line',
data: picdata,
showSymbol: false,
hoverAnimation: false,
markPoint: {
symbol: 'pin',

data: [
{ type: 'max', name: '最大值' },
{ type: 'min', name: '最小值' }
]
},
markLine: {
data: [
{ type: 'average', name: '平均值' }
]
}
}
]
};


pChart.setOption(option);
};
</script>
</html>
`
        return priceHtml;
    };
    if(frmId==9|frmId==10){  //京东手机页面处理
    var t2 = setInterval(function() {
        if ($("#id-pcprompt-mask")) {
            $("#id-pcprompt-mask").remove();
        }
        if ($("#halo-pcprompt-mask")) {
            $("#halo-pcprompt-mask").remove();
        }
        /*
        // 取消提示
        var gWd = null;
        gWd = getTargetByTAV("a","class","btn confirm btn_1");
        if (gWd !== null && typeof(gWd) === 'object') {
                gWd.click();
                clearInterval(t2);
            }else{}
        */
     },cyce)
    }

    if(chk==1){ //自动提交订单
        var t1 = setInterval(function() {
            var gXd = null;
            /*
            if (window.location.href.indexOf("jd.com")==-1){
                gXd = getTargetByTAV("a","class","go-btn");
            }else{
                gXd = getTargetById("order-submit");
            }
            */
            if (window.location.href.indexOf("jd.com")!=-1){
                 gXd = getTargetById("order-submit");
            }else if (window.location.href.indexOf("suning.com/order.do")!=-1){
                 gXd = getTargetByTAV("a","class","checkout-submit-btn cart-btn l");
            }else{
                gXd = getTargetByTAV("a","class","go-btn");
            }
            if (gXd !== null && typeof(gXd) === 'object') {
                gXd.click();
                clearInterval(t1);
            }else{}
        },cyce)
        }

    window.onload=function (){
        if((frmId == 1)|(frmId == 2)|(frmId == 7)){
            if (frmId == 1){
                ifLj = getTargetByTAV('div','class','tb-btn-wait');
            }else if(frmId == 2){
                ifLj = getTargetByTAV('div','class','tb-tqg');
            }else if(frmId == 7){
                ifLj = null;
            }
            if(ifLj == null ){
                //var nuLj = getTargetByTAV('div','class','tb-btn-buy tb-btn-sku tb-hidden');
                //if (nuLj!=null){}else{
                $('#AiceStart').prop('lastChild').nodeValue="优惠券";
                $('#AicePm').hide();
                ifYhq=1;
                //}
            }
        }
        if((frmId==3)|(frmId==4)){
            allck = getTargetById('J_SelectAll1');
            btnCart = getTargetById("J_Go");
            if (btnCart !== null && typeof(btnCart) === 'object') {
                btnBuy = btnCart;
            }

            if(ifRef==1&&mqMd==1){
                mqMode();
            }
        }
        if(frmId==5){
            $('#AiceStart').prop('lastChild').nodeValue="优惠券";
            $('#AicePm').hide();
            ifYhq=1;
        }
        if(frmId==6){
            allck = getTargetByTAV('input','class',"jdcheckbox");
            btnCart = getTargetByTAV('a','class',"submit-btn");
            if (btnCart !== null && typeof(btnCart) === 'object') {
                btnBuy = btnCart;
            }

            if(ifRef==1&&mqMd==1){
                mqMode();
            }
        }

        if(frmId==8){
            allck = getTargetById('chooseAllCheckBox');
            btnCart = getTargetByTAV('a','class',"checkout cart-btn");
            if (btnCart !== null && typeof(btnCart) === 'object') {
                btnBuy = btnCart;
            }

            if(ifRef==1&&mqMd==1){
                mqMode();
            }
        }


    }

    function getStyle(element, attr){
        if(element.currentStyle){
            return element.currentStyle[attr];
        }else{
            return window.getComputedStyle(element,null)[attr];
        }
    }

    function dateFormat(fmt, date) {
        let ret;
        let opt = {
            "Y+": date.getFullYear().toString(), // 年
            "m+": (date.getMonth() + 1).toString(), // 月
            "d+": date.getDate().toString(), // 日
            "H+": date.getHours().toString(), // 时
            "M+": date.getMinutes().toString(), // 分
            "S+": date.getSeconds().toString() // 秒
            // 有其他格式化字符需求可以继续添加,必须转化成字符串
        };

    if (/(Y+)/.exec(fmt)) fmt = fmt.replace(RegExp.$1, (date.getFullYear() + "").substr(4 - RegExp.$1.length));
         for (let k in opt) {
            ret = new RegExp("(" + k + ")").exec(fmt);
            if (ret) {
                fmt = fmt.replace(ret[1], (ret[1].length == 1) ? (opt[k]) : (("00" + opt[k]).substr(("" + opt[k]).length)));
            };
        };

    return fmt;
    }


    function getTargetById(t_id){
        var target = document.getElementById(t_id);
        return target;
    }

    function getTargetByTAV(t_tag,t_attr,t_value){
        var target = document.getElementsByTagName(t_tag);
        for(var i=0;i <target.length;i++){
            if(target[i].getAttribute(t_attr) == t_value){
                return target[i];
            }
        }
    }

    function trim(str){
        str = str.replace(/(^\s*)|(\s*$)/g, "");
        return str;
    }

    //写cookies
    function setCookie(name,value)
    {
        var Days = 30;
        var exp = new Date();
        exp.setTime(exp.getTime() + Days*24*60*60*1000);
        document.cookie = name + "="+ escape (value) + ";expires=" + exp.toGMTString();
    }

    function getCookie(name)
    {
        var arr,reg=new RegExp("(^| )"+name+"=([^;]*)(;|$)");
        if(arr=document.cookie.match(reg)){
            return unescape(arr[2]);
        }
        else{
            return null;
        }
    }

    function opWind(purl,pisweb,pname,phml){
        var url = purl;
        var name =pname;
        var iWidth=800;
        var iHeight=450;
        var iTop = (window.screen.height-30-iHeight)/2;
        var iLeft = (window.screen.width-10-iWidth)/2;
        var OpenWindow =window.open(url,name,'height='+iHeight+',,innerHeight='+iHeight+',width='+iWidth+',innerWidth='+iWidth+',top='+iTop+',left='+iLeft+',toolbar=no,menubar=no,scrollbars=auto,resizeable=no,location=no,status=no');
        if(pisweb==0){
            OpenWindow.document.write(phml);
            OpenWindow.document.close();
            OpenWindow.focus();
        }
    }

    function getYhqurl(vGoods,vSjid,fid){
        var exUrl = orgUrl + "&m=GMTourl&goodsid="+vGoods+"&sjid="+vSjid+"&fromid="+fid;
        console.log(exUrl);
        GM_xmlhttpRequest({
            url: exUrl,
            method: 'GET',
            timeout: 10000,
            headers: {
                'Content-Type': 'application/json',
                'Accept': 'application/json',
                'Cache-Control': 'public'
            },
            onload: function(res)
            {
                try{
                    const json = JSON.parse(res.responseText)
                    if (json.code==100){
                        if(json.msg.exurl.indexOf('http')==-1){}else{
                            GM_setValue("locUrl",window.location.href);
                            var exurl= document.getElementById("fname").contentWindow.postMessage({a: json.msg.exurl}, '*');
                        }
                    }
                }catch(e){
                }

            }
        });

    }


    var strJosn = null;
    unsafeWindow.fff= (d) => {
        strJosn = d;
    };

    const mqN =0 ;
    function mqMode()
    {
        console.log("开始盲抢");
        if (mqN>=60) return; //避免影响用户正常使用
        var divSel = null;
        if (window.location.href.indexOf("jd.com")!=-1|window.location.href.indexOf("suning.com")!=-1){
            if(allck !== null && typeof(allck) === 'object'){
                if (allck.checked==0){
                    allck.click();
                }
            }else{
                mqN++;
                mqMode();
                return;
            }
        }else{
            divSel = getTargetByTAV('div','class','select-all J_SelectAll');

            if (allck !== null && typeof(allck) === 'object') {
                if(divSel !== null && typeof(divSel) === 'object'){
                    allck.click();
                }else{
                    mqN++;
                    mqMode();
                    return;
                }
            }else{
                mqN++;
                mqMode();
                return;
            }
        }

        $('#AiceStart').prop('lastChild').nodeValue="等待抢购";

        window.setTimeout(function ()
                          {
            if (btnBuy !== null && typeof(btnBuy) === 'object') {
                btnBuy.click();
            }else{}

        }, 500);

    }

    function syncTime()
    {
        if (gostart==0) return;
        var timestamp = getCookie("ft_qgd");
        d8 = new Date();
        d8.setTime(timestamp);//读取抢拍时间

        starttime = new Date().getTime();
        GM_xmlhttpRequest({
            url: "https://t.alicdn.com/t/gettime?callback=fff",
            method: 'GET',
            timeout: 10000,
            headers: {
                'Content-Type': 'application/jsonp',
                'Accept': 'application/jsonp',
                'Cache-Control': 'public'
            },
            onload: function(responseDetails)
            {
                if (responseDetails.status == 200)
                {
                    //console.log(responseDetails.responseText);
                    //eval( responseDetails.responseText);
                    var strJosn = JSON.parse(responseDetails.responseText.replace('fff(','').replace(')',''));
                    //console.log(strJosn);
                    var result = strJosn;
                    endtime = new Date().getTime();
                    //服务器时间
                    var sd = new Date();
                    sd.setTime(result.time * 1000);
                    var ttx = d8 - sd;
                    if (ttx < 0)//已过1
                    {
                        alert("时间已过");
                        if (ttx> -2000) //避免重复刷页面
                        {
                            location.replace(location.href);
                        }
                    }else if (ttx > 60 * 1000 * 1)//1分钟才同步
                    {
                        console.log("距离抢购还有一段时间");
                        setTimeout(() =>
                                   {
                            //location.replace(location.href);
                            syncTime();
                        }, 10 * 1000);
                    }else if (ttx > 0) {
                        if (ttx <= mqBfTim * 1000 * 1 && mqMd ==1 ){
                            if(ifRef==0){
                                GM_setValue("ref",1);
                                location.replace(location.href);
                            }
                        }

                        $('#AiceStart').prop('lastChild').nodeValue="正在倒计时("+ttx/1000+"S)";
                        if (initsdtime_int == 0) {
                            initsdtime_int = parseInt(result.time);
                        }
                        if ((d8 - sd) <= 1000) {
                            console.log("等待抢购");
                            $('#AiceStart').prop('lastChild').nodeValue="等待抢购";

                            window.setTimeout(function ()
                                              {
                                if (btnBuy !== null && typeof(btnBuy) === 'object') {
                                    btnBuy.click();
                                }else{}

                            }, d8 - sd - bwtime);

                            window.setTimeout(function ()
                                              {
                                if (btnBuy !== null && typeof(btnBuy) === 'object') {
                                    btnBuy.click();
                                }else{}

                            }, d8 - sd - bwtime + 100); //重复提交一次确保提交到
                        }
                        else {
                            setTimeout(() =>
                                       {
                                syncTime();
                            }, 20);
                        }


                    }
                }

            }
        });

    }




})();