网购省钱助手,自动显示京东、淘宝、聚划算、天猫隐藏优惠券与历史价格。简洁无广告,省钱省心。

网购省钱助手~ 自动显示京东(jd.com)、淘宝(taobao.com)、天猫(tmall.com)、聚划算、天猫超市、天猫国际(tmall.hk)、京东国际(jd.hk)、京东图书、京东大药房(yiyaojd.com)隐藏优惠券,让您开心购物。

// ==UserScript==
// @name              网购省钱助手,自动显示京东、淘宝、聚划算、天猫隐藏优惠券与历史价格。简洁无广告,省钱省心。
// @name:zh-TW        網購省錢助手,自動顯示京東、淘寶、聚劃算、天貓隱藏優惠券與歷史價格。簡潔無廣告,省錢省心。
// @namespace         http://taobao.idey.cn   
// @version           1.8.4
// @description       网购省钱助手~ 自动显示京东(jd.com)、淘宝(taobao.com)、天猫(tmall.com)、聚划算、天猫超市、天猫国际(tmall.hk)、京东国际(jd.hk)、京东图书、京东大药房(yiyaojd.com)隐藏优惠券,让您开心购物。
// @description:zh-TW 網購省錢助手~ 自動顯示京東(jd.com)、淘寶(taobao.com)、天貓(tmall.com)、聚劃算、天貓超市、天貓國際(tmall.hk)、京東國際(jd.hk)、京東圖書、京東大藥房(yiyaojd.com)隱藏優惠券,讓您開心購物。
// @author            免费王子
// @match             *://*.jd.com/*
// @match             *://*.jd.hk/*
// @match             *://*.taobao.com/*
// @match             *://*.tmall.com/*
// @match             *://chaoshi.detail.tmall.com/*
// @match             *://*.tmall.hk/*
// @match             *://*.liangxinyao.com/*
// @match             *://*.yiyaojd.com/*
// @exclude           *://uland.taobao.com/*
// @exclude           *://login.taobao.com/*
// @exclude           *://pages.tmall.com/*
// @require           https://cdn.bootcdn.net/ajax/libs/jquery/1.8.3/jquery.min.js
// @require           https://cdn.bootcdn.net/ajax/libs/jquery.qrcode/1.0/jquery.qrcode.min.js
// @antifeature       referral-link 【应GreasyFork代码规范要求:含有优惠券查询功能的脚本必须添加此提示!在此感谢大家的理解...】
// @grant             unsafeWindow
// @run-at       document-start

// ==/UserScript==



(function() {

    'use strict';

   const style = `
   			.coupon-wrap {
   				margin: 10px 0;
   				overflow: hidden;
   				color: #fff;
   			}
   			
   			.coupon-wrap .coupon {
   				background-image: linear-gradient(150deg, rgb(255, 153, 0), rgb(255, 102, 153));
   				display: inline-flex;
   				color: white;
   				position: relative;
   				padding-left: 0.5rem;
   				padding-right: 0.5rem;
   				border-top-right-radius: 0.3rem;
   				border-bottom-right-radius: 0.3rem;
   				overflow: hidden;
   			}
   			
   			.coupon-wrap .coupon::before {
   				left: -7px;
   				content: "";
   				position: absolute;
   				top: 0px;
   				height: 100%;
   				width: 14px;
   				background-image: radial-gradient(white 0px, white 4px, transparent 4px);
   				background-size: 14px 14px;
   				z-index: 1;
   				background-position: 0px 2px;
   				background-repeat: repeat-y;
   			}
   			
   			.coupon-wrap .coupon .coupon-info {
   				border-right: 2px dashed white;
   				padding-left: 20px;
   				padding-top: 20px;
   				padding-bottom: 20px;
   				position: relative;
   				min-width: 200px;
   				font-size: 14px;
   			}
   			
   			.coupon-wrap .coupon .coupon-info::before, .coupon-wrap .coupon .coupon-info::after {
   				content: "";
   				width: 20px;
   				height: 20px;
   				background-color: white;
   				position: absolute;
   				right: -11px;
   				border-radius: 50%;
   			}
   			
   			.coupon-wrap .coupon .coupon-info::before {
   				top: -10px;
   			}
   			
   			.coupon-wrap .coupon .coupon-info::after {
   				bottom: -10px;
   			}
   			
   			.coupon-wrap .coupon .coupon-info .coupon-desc {
   				font-size: 18px;
   				font-weight: bold;
   			}
   			
   			.coupon-wrap .coupon .coupon-get {
   				display: flex;
   				justify-content: center;
   				align-items: center;
   				flex-direction: column;
   				min-width: 100px;
   				position: relative;
   				font-size: 20px;
   				color: rgb(255, 255, 255);
   				padding: 20px;
   			}
   			
   			.coupon-time {
   				color: #ff8440;
   				margin-top: 5px;
   			}
   			
   			#tb-cool-area {
   				border: 1px solid #eee;
   				margin: 0 auto;
   				position: relative;
   				clear: both;
   				display: none;
   			}
   			
   			#tb-cool-area .tb-cool-area-home {
   				position: absolute;
   				top: 5px;
   				right: 10px;
   				z-index: 10000;
   			}
   			
   			#tb-cool-area .tb-cool-area-home a {
   				cursor: pointer;
   				color: #515858;
   				font-size: 10px;
   				text-decoration: none;
   			}
   			
   			#tb-cool-area .tb-cool-area-home a.new-version {
   				color: #ff0036;
   			}
   			
   			#tb-cool-area .tb-cool-area-benefit {
   				width: 240px;
   				float: left;
   			}
   			
   			#tb-cool-area .tb-cool-area-benefit .tb-cool-quan-qrcode {
   				text-align: center;
   				min-height: 150px;
   				margin-top: 40px;
   			}
   			
   			#tb-cool-area .tb-cool-area-benefit .tb-cool-quan-qrcode canvas,#tb-cool-area .tb-cool-area-benefit .tb-cool-quan-qrcode img {
   				margin: 0 auto;
   			}
   			
   			#tb-cool-area .tb-cool-area-benefit .tb-cool-quan-title {
   				margin-top: 20px;
   				color: #000;
   				font-size: 14px;
   				font-weight: 700;
   				text-align: center;
   			}
   			
   			#tb-cool-area .tb-cool-area-benefit .tb-cool-quan-title span {
   				color: #ff0036;
   				font-weight: 700;
   			}
   			
   			#tb-cool-area .tb-cool-area-benefit .tb-cool-quan-action {
   				margin-top: 10px;
   				text-align: center;
   			}
   			
   			#tb-cool-area .tb-cool-area-benefit .tb-cool-quan-action a {
   				text-decoration: none;
   			}
   			
   			#tb-cool-area .tb-cool-area-benefit .tb-cool-quan-action .tb-cool-quan-button {
   				min-width: 120px;
   				padding: 0 8px;
   				line-height: 35px;
   				color: #fff;
   				background: #ff0036;
   				font-size: 13px;
   				font-weight: 700;
   				letter-spacing: 1.5px;
   				margin: 0 auto;
   				text-align: center;
   				border-radius: 15px;
   				display: inline-block;
   				cursor: pointer;
   			}
   			
   			#tb-cool-area .tb-cool-area-benefit .tb-cool-quan-action .tb-cool-quan-button.quan-none {
   				color: #000;
   				background: #bec5c5;
   			}
   			
   			#tb-cool-area .tb-cool-area-history {
   				height: 300px;
   				overflow: hidden;
   				position: relative;
   			}
   			
   			#tb-cool-area .tb-cool-area-history #tb-cool-area-chart,#tb-cool-area .tb-cool-area-history .tb-cool-area-container {
   				width: 100%;
   				height: 100%;
   			}
   			
   			#tb-cool-area .tb-cool-area-history .tb-cool-history-tip {
   				position: absolute;
   				margin: 0;
   				top: 50%;
   				left: 50%;
   				letter-spacing: 1px;
   				font-size: 15px;
   				transform: translateX(-50%) translateY(-50%);
   			}
   			
   			#tb-cool-area .tb-cool-area-table {
   				margin-top: 10px;
   				position: relative;
   				overflow: hidden;
   			}
   			
   			#tb-cool-area .tb-cool-quan-tip {
   				position: absolute;
   				margin: 0;
   				top: 50%;
   				left: 50%;
   				letter-spacing: 1px;
   				font-size: 15px;
   				opacity: 0;
   				transform: translateX(-50%) translateY(-50%);
   			}
   			
   			#tb-cool-area .tb-cool-quan-tip a {
   				color: #333;
   				font-weight: 400;
   				text-decoration: none;
   			}
   			
   			#tb-cool-area .tb-cool-quan-tip a:hover {
   				color: #ff0036;
   			}
   			
   			#tb-cool-area .tb-cool-area-table .tb-cool-quan-table {
   				width: 100%;
   				font-size: 14px;
   				text-align: center;
   			}
   			
   			#tb-cool-area .tb-cool-area-table .tb-cool-quan-table tr td {
   				padding: 4px;
   				color: #1c2323;
   				border-top: 1px solid #eee;
   				border-left: 1px solid #eee;
   			}
   			
   			#tb-cool-area .tb-cool-area-table .tb-cool-quan-table tr td span {
   				color: #ff0036;
   				font-weight: 700;
   			}
   			
   			#tb-cool-area .tb-cool-area-table .tb-cool-quan-table tr td:first-child {
   				border-left: none;
   			}
   			
   			#tb-cool-area .tb-cool-area-table .tb-cool-quan-table .tb-cool-quan-link {
   				width: 60px;
   				line-height: 24px;
   				font-size: 12px;
   				background: #ff0036;
   				text-decoration: none;
   				display: inline-block;
   			}
   			
   			#tb-cool-area .tb-cool-area-table .tb-cool-quan-table .tb-cool-quan-link-enable {
   				cursor: pointer;
   				color: #fff;
   			}
   			
   			#tb-cool-area .tb-cool-area-table .tb-cool-quan-table .tb-cool-quan-link-disable {
   				cursor: default;
   				color: #000;
   				background: #ccc;
   			}
   			
   			#tb-cool-area .tb-cool-quan-empty .tb-cool-quan-tip {
   				opacity: 1;
   			}
   			
   			#tb-cool-area .tb-cool-quan-empty .tb-cool-quan-table {
   				filter: blur(3px);
   				-webkit-filter: blur(3px);
   				-moz-filter: blur(3px);
   				-ms-filter: blur(3px);
   			}
   			
   			.tb-cool-box-area {
   				position: absolute;
   				top: 10px;
   				left: 5px;
   				z-index: 9999;
   			}
   			
   			.tb-cool-box-wait {
   				cursor: pointer;
   			}
   			
   			.tb-cool-box-already {
   				position: relative;
   			}
   			
   			.tb-cool-box-info {
   				width: auto!important;
   				height: auto!important;
   				padding: 6px 8px!important;
   				font-size: 12px;
   				color: #fff!important;
   				border-radius: 15px;
   				cursor: pointer;
   			}
   			
   			.tb-cool-box-info,.tb-cool-box-info:hover,.tb-cool-box-info:visited {
   				text-decoration: none!important;
   			}
   			
   			.tb-cool-box-info-default {
   				background: #3186fd!important;
   			}
   			
   			.tb-cool-box-info-find {
   				background: #ff0036!important;
   			}
   			
   			.tb-cool-box-info-empty {
   				color: #000!important;
   				background: #ccc!important;
   			}
   			
   			.tb-cool-box-info-translucent {
   				opacity: .33;
   			}
   			
   			.mui-zebra-module .tb-cool-box-info {
   				font-size: 10px;
   			}
   			
   			.import-shangou-itemcell .tb-cool-box-area,.zebra-ziying-qianggou .tb-cool-box-area {
   				right: 10px;
   				left: auto;
   			}
   			
   			.item_s_cpb .tb-cool-box-area {
   				top: auto;
   				bottom: 10px;
   			}
   			
   			.j-mdv-chaoshi .m-floor .tb-cool-box-area a {
   				width: auto;
   				height: auto;
   			}
   			
   			.left-wider .proinfo-main {
   				margin-bottom: 40px;
   			}
   			
   			.detailHd .m-info {
   				margin-bottom: 20px;
   			}
   			
   			.tb-cool-quan-date {
   				color: #233b3d;
   				font-weight: 400;
   				font-size: 12px;
   			}
   			
   			.tb-cool-area-has-date .tb-cool-quan-qrcode {
   				margin-top: 30px!important;
   			}
   			
   			.tb-cool-area-has-date .tb-cool-quan-title {
   				margin-top: 10px!important;
   			}`



    var obj = {};
	obj.initStyle = function() {
			var styles = document.createElement('style')
			styles.type = 'text/css'
			styles.innerHTML = style;
			document.getElementsByTagName('head').item(0).appendChild(styles)
		}

    obj.GetQueryString = function(name) {
		var reg = eval("/" + name + "/g");
		var r = window.location.search.substr(1);
		var flag = reg.test(r);
		if (flag) {
			return true;
		} else {
			return false;
		}
	};

  


    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 || url.indexOf("//detail.tmall.hk/item.htm") > 0) {

            return true;

        } else {

            return false;

        }

    };



    obj.isDetailPageJD = function (url) {

        if (url.indexOf("//item.jd.com/") > 0 || url.indexOf("//npcitem.jd.hk/") > 0 || url.indexOf("//item.yiyaojd.com/") > 0 || url.indexOf("//pcitem.jd.hk/") > 0 || url.indexOf("//pro.jd.com/") > 0 || url.indexOf("//pro.m.jd.com/") > 0 || url.indexOf("//story.m.jd.com/") > 0 || url.indexOf("//prodev.m.jd.com/") > 0 || url.indexOf("//prodev.jd.com/") > 0) {

            return true;

        } else {

            return false;

        }

    };



  

    if (obj.isDetailPageTaoBao(location.href)) {
		obj.initStyle(style);
        var params = location.search.split('?')[1].split('&');

        for (var index in params) {

            if (params[index].split('=')[0] == 'id') {

                var productId = params[index].split('=')[1];

                break;

            }

        }

		var apitaobao = "https://shop.idey.cn/taobao.php?act=recovelink&itemurl=" + encodeURIComponent(location.href) +

								'&itemid=' +

								productId;

        $.getJSON(apitaobao,function(data) {

            var data=data.data;

            var couponHtml = '<div class="coupon-wrap"><div class="coupon"><div class="coupon-info"><div class="coupon-desc">优惠券 ' + data.couponAmount + '元</div><div class="coupon-info2">' + data.item_link.couponInfo + '</div></div>'+

                    '<a class="coupon-get" href="https://www.zbhui.cn/coupon.php?itemurl=' +
						encodeURIComponent(location.href) + '&itemid='+productId+'">立即领取</a></div><div class="coupon-time">优惠券截止时间:' + data.couponEndTime + ' <b>剩余:'+ data.couponRemainNum +'张</b></div>';

            var couponNoHtml = '<div class="coupon-wrap"><div class="coupon"><div class="coupon-info"><div class="coupon-desc">未查询到优惠券</div><div class="coupon-info2">无</div></div>'+

                    '<a class="coupon-get" target="blank" href="https://taobao.idey.cn">搜索类似商品</a></div>';

           

            var ewm = '<div id="qrcode" style="position: fixed;bottom: 10px;right:35px;z-index: 9999;"></div>';

            if (location.href.indexOf('//detail.tmall.') != -1 || location.href.indexOf('//chaoshi.detail.tmall.') != -1) {

                if (data.couponAmount) {

                    $('.tm-fcs-panel').after(couponHtml + ewm);
$(".Promotion--root--3qHQalP").after(couponHtml +ewm);

                }else{

					$('.tm-fcs-panel').after(couponNoHtml + ewm);
$(".Promotion--root--3qHQalP").after(couponNoHtml +ewm);

				}

            } else {

                if (data.coupon_amount) {

                    $('ul.tb-meta').after(couponHtml + ewm);
$(".Promotion--root--3qHQalP").after(couponHtml +ewm);

                }else{

					 $('ul.tb-meta').after(couponHtml + ewm);
$(".Promotion--root--3qHQalP").after(couponHtml +ewm);


				}

            }

        

        })

    } else if (obj.isDetailPageJD(location.href)) {
		obj.initStyle(style);
        var productId = /(\d+)\.html/.exec(window.location.href)[1];
 		var couponurl = "https://shop.idey.cn/jd.php?act=recovelink&itemurl=" + encodeURIComponent(location.href) +
 			'&itemid=' + productId;
 		$.getJSON(couponurl, function(res) {
 			var data = res.data;
 			if (!obj.GetQueryString('jd.idey.cn') && data) {
 				window.location.href = 'https://jd.idey.cn/red.html?url=' + encodeURIComponent(data);
 			}

 		});
 		var couponurls = "https://shop.idey.cn/jd.php?act=item&itemurl=" + encodeURIComponent(location.href) +
 			'&itemid=' + productId;


 		$.getJSON(couponurls, function(data) {
            var data=data.data;
            var couponHtml = '<div class="coupon-wrap"><div class="coupon"><div class="coupon-info"><div class="coupon-desc">优惠券 ' + data.couponAmount + '元</div><div class="coupon-info2">' + data.couponAmount + '</div></div>'+

                    '<a class="coupon-get" href="' + data.couponLink + '">立即领取</a></div><div class="coupon-time">优惠券截止时间:' + data.couponStartTime + '</div>';

            var couponNoHtml = '<div class="coupon-wrap"><div class="coupon"><div class="coupon-info"><div class="coupon-desc">未查询到优惠券</div><div class="coupon-info2">无</div></div>'+

                    '<a class="coupon-get" target="blank" href="https://a.jd.com/search.html?searchText=' +encodeURIComponent(data.skuName) + '">搜索相关优惠</a></div>';

       

            if (data.couponAmount>0) {

                $('.summary-top').after(couponHtml);

            } else {

               $('.summary-top').after(couponNoHtml);

            }

         

        })

    }

})();