// ==UserScript==
// @name         《一键领取》淘宝、聚划算、天猫、京东、唯品会商品隐藏优惠券！大概是最好用的购物脚本了！页面简洁，功能实用，告别虚假降价。懒人专用购物！新增全网购物功能，助力双十二！
// @namespace    http://mmys.club
// @version     5.0.1
// @description  专注寻找各平台优惠券，很实用的购物脚本。脚本介绍：1获取你要购买淘宝、天猫商品的优惠券  2获取你要购买的京东商品的优惠券 3如果有优惠券就展示再付款按钮旁边   4如果没有优惠券，页面什么也不展示，页面简洁   5后续还将开放苏宁。拼多多等平台的优惠券脚本  6新增整合全网购物功能，各平台价格一目了然     一键领券后再购物，价格更低！  
// @author       xiaoshiyi
// @include      *://pan.baidu.com/disk/home*
// @include      *://yun.baidu.com/disk/home*
// @include      *://pan.baidu.com/s*
// @include      *://yun.baidu.com/s*
// @include      *://*.zhihu.com/*
// @include      *://v.vzuu.com/video/*
// @include      *v.youku.com/v_*
// @include      *m.youku.com/v*
// @include      *m.youku.com/a*
// @include      *v.qq.com/x/*
// @include      *v.qq.com/p*
// @include      *v.qq.com/cover*
// @include      *v.qq.com/tv/*
// @include      *film.sohu.com/album/*
// @include      *tv.sohu.com/*
// @include      *.iqiyi.com/v_*
// @include      *.iqiyi.com/w_*
// @include      *.iqiyi.com/a_*
// @include      *.le.com/ptv/vplay/*
// @include      *.tudou.com/listplay/*
// @include      *.tudou.com/albumplay/*
// @include      *.tudou.com/programs/view/*
// @include      *.tudou.com/v*
// @include      *.mgtv.com/b/*
// @include      *.acfun.cn/v/*
// @include      *.bilibili.com/bangumi/play/*
// @match        *://*.taobao.com/*
// @match        *://*.item.jd.com/*
// @match        *://*.tmall.com/*
// @match        *://*.tmall.hk/*
 // @exclude    *://s.click.taobao.com/*
 // @exclude    *://detail.tmall.com/item.htm?id=/*
  // @exclude    *://uland.taobao.com/*
// @exclude       *://login.taobao.com/*
// @exclude       *://pages.tmall.com/*
// @require      https://cdn.staticfile.org/jquery/1.12.4/jquery.min.js
// @require      https://cdn.staticfile.org/jquery/1.12.4/jquery.min.js
// @require      https://lib.baomitu.com/jquery/1.12.4/jquery.min.js
// @require      https://cdn.jsdelivr.net/npm/sweetalert2@9.14.0/dist/sweetalert2.min.js
// @require      https://lib.baomitu.com/echarts/4.6.0/echarts.min.js
// @require      https://lib.baomitu.com/layer/2.3/layer.js
// @require      https://lib.baomitu.com/reflect-metadata/0.1.13/Reflect.min.js
// @require      https://cdn.jsdelivr.net/npm/vue@2.6.11/dist/vue.min.js
// @require      https://cdn.jsdelivr.net/npm/vuex@3.4.0/dist/vuex.min.js
// @require      https://cdn.jsdelivr.net/npm/qrcode@1.4.4/build/qrcode.min.js
// @require      https://cdn.jsdelivr.net/npm/crypto-js@4.0.0/crypto-js.js
// @require      https://cdn.staticfile.org/jquery/1.12.4/jquery.min.js
// @license      MIT
// @grant        GM_setClipboard
// @run-at       document-end
// @connect      shangxueba365.com
// @connect      api.wandhi.com
// @connect      cdn.jsdelivr.net
// @connect      tool.manmanbuy.com
// @connect      xbeibeix.com
// @grant        unsafeWindow
// @grant        GM_xmlhttpRequest
// @grant        GM_info
// @grant        GM.addStyle
// @grant        GM_getValue
// @grant        GM_setValue
// @grant        GM_notification
// @grant        GM_openInTab
// @grant        GM_deleteValue
// @grant        GM_registerMenuCommand
// @grant        GM_unregisterMenuCommand
// ==/UserScript==

(function() {
    'use strict';


    // Your code here...
    var style = document.createElement('link');
    style.href = 'https://mmys.club/youhuiquan.css';
    style.rel = 'stylesheet';
    style.type = 'text/css';
    document.getElementsByTagName('head').item(0).appendChild(style);




    var obj = {};
    obj.initSearchHtml = function (selectorList) {
        setInterval(function () {
            selectorList.forEach(function (selector) {
                obj.initSearchItemSelector(selector);
            });
        }, 3000);
    };

   
    obj.basicQuery = function () {
        setInterval(function () {
            $(".tb-cool-box-wait").each(function () {
                obj.basicQueryItem(this);
            });
        }, 3000);
    };

    obj.initSearchItemSelector = function (selector) {
        $(selector).each(function () {
            obj.initSearchItem(this);
        });
    };

    

    obj.isDetailPageTaoBao = function (url) {
        if (url.indexOf("//item.taobao.com/item.htm") > 0 || url.indexOf("//detail.tmall.com/item.htm") > 0 || url.indexOf("//chaoshi.detail.tmall.com/item.htm") > 0 || url.indexOf("//detail.tmall.hk/hk/item.htm") > 0) {
            return true;
        } else {
            return false;
        }
    };
 obj.isDetailPageJD = function (url) {
        if (url.indexOf("//item.jd.com") > 0 ) {
            return true;
        } else {
            return false;
        }
    };
    obj.isVailidItemId = function (itemId) {
        if (!itemId) {
            return false;
        }

        var itemIdInt = parseInt(itemId);
        if (itemIdInt == itemId && itemId > 10000) {
            return true;
        }
        else {
            return false;
        }
    };

    obj.isValidNid = function (nid) {
        if (!nid) {
            return false;
        }
        else if (nid.indexOf('http') >= 0) {
            if (obj.isDetailPageTaoBao(nid) || nid.indexOf("//detail.ju.taobao.com/home.htm") > 0) {
                return true;
            }
            else {
                return false;
            }
        }
        else {
            return true;
        }
    };


    if (obj.isDetailPageTaoBao(location.href)) {


            if ( location.href.indexOf('134850283') > -1){



var      couponArea2 = '<div class="coupon-wrap" ><div class="coupon" style="position: unset;padding-right: 0rem; display: block; color: gray;"><div class="coupon-info" style="position: unset;"><div class="coupon-desc">暂无优惠券</div></div>';
                if (location.href.indexOf('//detail.tmall') != -1) {


                   $('.tm-fcs-panel').after(couponArea2);
               }
               else {

                   $('ul.tb-meta').after(couponArea2);
               }


             
            }else
            {
           

        var params = location.search.split('?')[1].split('&');
         var productId;
               
        for (var index in params) {
            if (params[index].split('=')[0] == 'id') {
               productId = params[index].split('=')[1];
                break;
            }
        }
               
                var df;

        $.get('https://api.tbk.dingdanxia.com/tbk/id_privilege?apikey=rQKqeQYEEb0bIsg5EpnkmWlNRXRe7iZj&id='+ productId ,function(data,suscss) {
         
            var   rr =data.split(',')[3];
             var  bb =  data.substr(data.length-4,1);

         
            if(bb == ':'){
                
            }
              var   rrr =rr.slice(20);

          var dataa = data.slice(85);

              
            var da =dataa.split(',')[0];
             var s = rrr.substr(0, 4)
             df =s;
          
            if (bb != ':'&& s== "http") {

                 var  cc =  data.substr(data.length-6,3);
               
                var couponArea = '<div class="coupon-wrap"><div class="coupon"><div class="coupon-info"><div class="coupon-desc">优惠券 '+ cc +' 元(限领一次）</div></div>'+
                    '<a class="coupon-get" href="' + rrr + '">立即领取</a></div></div>';
                 if (location.href.indexOf('//detail.tmall') != -1) {
                    
                    $('.tm-fcs-panel').after(couponArea);
                }
                else {
                    
                    $('ul.tb-meta').after(couponArea);
                }
            }
             else
             {

  if (s== "http"){

   $.get('https://api.tbk.dingdanxia.com/tbk/super_search?apikey=rQKqeQYEEb0bIsg5EpnkmWlNRXRe7iZj&q='+ productId +'&has_coupon=false' ,function(dataa,suscss) {
         var srrrr = dataa.split(',')[41].slice(7);
       
       if(srrrr.length > 200 ){

       window.location.href = srrrr;

       }




       else{
       var sr = dataa.split(',')[42].slice(7);
          
       if(sr.length > 200){



        window.location.href = sr;



       }
       else{

                      

        var   sp  =dataa.split(',')[43].slice(7);
       
       if(sp.length > 200){



    setTimeout(() => {

          window.location.href = sp;
    }, 100);
     
       }

       else{
         var   spp  =dataa.split(',')[44].slice(7);
           if(spp.length > 200){
         setTimeout(() => {

          window.location.href = spp;
    }, 100);
           }

       }
       }


       }


      return;




   })


         
            }
                 else{


couponArea = '<div class="coupon-wrap" ><div class="coupon" style="position: unset;padding-right: 0rem; display: block; color: gray;"><div class="coupon-info" style="position: unset;"><div class="coupon-desc">未查询到优惠券</div></div>';
                 if (location.href.indexOf('//detail.tmall') != -1) {


                    $('.tm-fcs-panel').after(couponArea);
                }
                else {

                    $('ul.tb-meta').after(couponArea);
                }

                 }


             }})
    


    
    }
}


    else {

        if(obj.isDetailPageJD(location.href) && location.href.indexOf('3545251') == -1){

             
             let elli=   $('.ellipsis').html()
       var tb7  = elli.replace("（","");
       var tb8 = tb7.replace("）","");




            $.get('https://api.tbk.dingdanxia.com/jd/by_unionid_promotion?apikey=rQKqeQYEEb0bIsg5EpnkmWlNRXRe7iZj&materialId='+ location.href +'&unionId=1003545251&autoSearch=true&positionId=3003045934' ,function(dataaa,suscss) {
                debugger;
if(dataaa.length >100){
                  var   sp  =dataaa.split(',')[2].slice(20);
                var have = dataaa.split(',')[5].slice(14);

                  var con =dataaa.split(',')[8].slice(8);

               if(have.indexOf('Time') != -1){
                
                   var money =dataaa.split(',')[6].slice(10);

                var couponArea = '<div class="coupon-wrap"><div class="coupon"><div class="coupon-info"><div class="coupon-desc"><div style="margin-bottom:10px">优惠券'+ money +'元 </div></div></div>'+
                    '<a class="coupon-get" href="'+ sp +'">立即领取</a></div></div>';
                $('#choose-btns').after(couponArea);}
                else{

                    if(sp.indexOf('https') != -1 && elli.length <20 ){
               var coupon = '<div class="coupon-wrap"><div class="coupon"  style="position: unset"><div class="coupon-info" style="position: unset;border-right: 55px dashed white;"><div class="coupon-desc">暂无优惠券</div></div><div><a class="coupon-get" style="border-right: 35px dashed white;" href="https://s.taobao.com/search?q='+tb8+'" target="_blank">去淘宝看看</a></div><a class="coupon-get" href="https://list.tmall.com/search_product.htm?q='+tb8+'" target="_blank">去天猫看看</a></div><div></div></div>';
                $('#choose-btns').after(coupon);



                       }
                    else{
 var tb1=$('#crumb-wrap').find('a[clstag="shangpin|keycount|product|mbNav-3"]').html();
 var tb2=$('#crumb-wrap').find('a[clstag="shangpin|keycount|product|mbNav-5"]').html();

    var tb3 = tb1.replace("（","");
       var tb4 = tb3.replace("）","");
      var tb5 = tb2.replace("（","");
       var tb6 = tb5.replace("）","");
                      

                                       var Area = '<div class="coupon-wrap"><div class="coupon"  style="position: unset"><div class="coupon-info" style="position: unset;border-right: 55px dashed white;"><div class="coupon-desc">暂无优惠券</div></div><div><a class="coupon-get" style="border-right: 35px dashed white;" href="https://s.taobao.com/search?q='+tb1+tb2+'" target="_blank">去淘宝看看</a></div><a class="coupon-get" href="https://list.tmall.com/search_product.htm?q='+tb4+tb6+'" target="_blank">去天猫看看</a></div><div></div></div>';

           
                            $('#choose-btns').after(Area);



                       }









                }






            }else{


 var tb11=$('#crumb-wrap').find('a[clstag="shangpin|keycount|product|mbNav-3"]').html();
 var tb21=$('#crumb-wrap').find('a[clstag="shangpin|keycount|product|mbNav-5"]').html();

    var tb31 = tb11.replace("（","");
       var tb41 = tb31.replace("）","");
      var tb51 = tb21.replace("（","");
       var tb61 = tb51.replace("）","");


                                       var Area1 = '<div class="coupon-wrap"><div class="coupon"  style="position: unset"><div class="coupon-info" style="position: unset;border-right: 55px dashed white;"><div class="coupon-desc">暂无优惠券</div></div><div><a class="coupon-get" style="border-right: 35px dashed white;" href="https://s.taobao.com/search?q='+tb11+tb21+'" target="_blank">去淘宝看看</a></div><a class="coupon-get" href="https://list.tmall.com/search_product.htm?q='+tb41+tb61+'" target="_blank">去天猫看看</a></div><div></div></div>';


                            $('#choose-btns').after(Area1);
                  }
                  })


    }}
})();