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

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

// ==UserScript==
// @name              网购省钱助手,自动显示京东、淘宝、聚划算、天猫隐藏优惠券与历史价格。简洁无广告,省钱省心。
// @name:zh-TW        網購省錢助手,自動顯示京東、淘寶、聚劃算、天貓隱藏優惠券與歷史價格。簡潔無廣告,省錢省心。
// @namespace         https://api.azkou.cn/ts.html
// @version           1.0.3
// @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             *://*.taobao.com/*
// @match             *://*.tmall.com/*
// @match             *://chaoshi.detail.tmall.com/*
// @match             *://*.tmall.hk/*
// @match             *://*.liangxinyao.com/*
// @match             *://*.jd.com/*
// @match             *://*.jd.hk/*
// @match             *://*.yiyaojd.com/*
// @match             *://*.vip.com/*
// @match             *://*.vipglobal.hk/*
// @exclude           *://login.taobao.com/*
// @exclude           *://login.tmall.com/*
// @exclude           *://uland.taobao.com/*
// @exclude           *://pages.tmall.com/*
// @exclude           *://wq.jd.com/*
// @connect           azkou.cn
// @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
// @grant             GM_xmlhttpRequest
// @grant             GM_addStyle
// @license           AGPL
// ==/UserScript==
(function() {
	'use strict';
	let base={
		href:location.href,
		css:`.coupon-box{margin-top:5px;align-items: center;background-image: linear-gradient(150deg, rgb(255, 153, 0), rgb(255, 102, 153));max-width: 380px;color: white;border-radius: 6px;}
		.coupon-center{display:flex;}
		.coupon-money{display: flex;align-items: center;justify-content: center;height:70px}
		.coupon-info{display: flex;flex-direction: column;justify-content: center;min-width: 170px;line-height: 20px;}
		.coupon-btn{justify-content: center;align-items: center;display: flex;height:70px}
		.coupon-btn a{display: flex;font-size: 20px;color: white;padding: 5px; }
		.coupon-btn a:hover{color:rgb(255,153,0)}
		.fsize30{font-size:30px}
		.fsize22{font-size:22px}
		.mg10{margin-top:10px}
                .mg20{margin-top:20px}
		`,
		warp:['.gl-warp >li','.mc .clearfix >li','#J-superkillGoodslist >li','.more2_list >li','.pd_common_wrap'],
		searchList:[],
		searchTempList:[],
		searchKey:0,
		num:5,
		getValue(name) {
			return GM_getValue(name);
		},
		setValue(name, value) {
			GM_setValue(name, value);
		},
		sleep(time){
			return new Promise((resolve) => setTimeout(resolve, time));
		},
		getParam(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;
			}
		},
		api:'https://api.azkou.cn/',
		tpi:'https://ts.azkou.cn/',
		post:async(url,data,headers) => {
						return new Promise((resolve, reject) => {
								 GM_xmlhttpRequest({
									method: "POST",
									url,
									data,
									headers,
									responseType:'json',
									onload: (res) => {
										resolve(res.response || res.responseText);
									},
									onerror: (err) => {
										reject(err);
									},
								});

							});
		},
		addStyle(style){
			GM_addStyle(style);
		},
		removeClass(html){
			let node_arr = html.split('|');
			for (let i = 0; i < node_arr.length; i++) {
				$(node_arr[i]).remove();
			}
		},
		removeHtml(html){
			base.removeClass(html);
			base.sleep(500).then(()=>{
				base.removeClass(html);
			})
		},
		jumpUrl:(url)=>{
					var form=null;
					if (document.getElementById('redirect_form')) {
							form = document.getElementById('redirect_form');
							form.action = url;
						} else {
							form = document.createElement('form');
							form.action =url;
							form.target = '_blank';

							form.method = 'POST';
							form.setAttribute("id", 'redirect_form');
							document.body.appendChild(form);
						}
						form.submit();
						form.action = "";
						form.parentNode.removeChild(form);
		},
		addClassHtml(warp,html){
			let node_arr = warp.split('|');
			for (let i = 0; i < node_arr.length; i++) {
				if($('div').is(node_arr[i])){
					$(node_arr[i]).after(html);
					break;
				}
			}
		},
		search(){
			base.warp.forEach(function(item){
				let list=$(item);
				list.map(function(key,items){
					if($(items).attr('data-md5-value')!='yes'){
						base.searchList.push(items);
						base.searchTempList.push(items);
						$(items).attr('data-md5-key',base.searchKey);
						$(items).attr('data-md5-value','yes');
						base.searchKey++;
					}
				})
			})
			let requestTemp=base.searchTempList.splice(0,base.num);
			let requestList=[];

			requestTemp.forEach(function(item,key){
				let temp={};
				temp['href']=$(item).find('a:first').attr('href');
				temp['md5']=$(item).attr('data-md5-key');
				requestList.push(temp);
			})
			if(requestList.length>0){
				base.post(`${base.api}?type=jdsearch&`,JSON.stringify({data:requestList}),{}).then((res)=>{
					if(res.status==1){
						res.data.map(function(item){
			                if(item.url){
			                    $(base.searchList[item.md5]).find('a').bind("click", function(e) {
			                        e.preventDefault();
			                        base.jumpUrl(item.url);
			                    })
			                }
						})
					}
				})
			}
		}

	}
	base.addStyle(base.css);
	if (base.href.indexOf("//item.taobao.com/item") != -1 || base.href.indexOf("//detail.tmall.com/item") != -1 || base.href.indexOf("//chaoshi.detail.tmall.com/item") != -1 || base.href.indexOf("//detail.tmall.hk/hk/item") != -1 || base.href.indexOf("//detail.tmall.hk/item") != -1) {
		$.getJSON(base.api+'?type=tbitem&url='+encodeURIComponent(base.href), function(res) {
			let html='';
			if(res.status==1){
				 html+='<div class="coupon-box"><div class="coupon-center"><div class="coupon-money" style="width: 100px;"><div></div><div class="fsize30">'+res.money+'</div></div><div class="coupon-info"><div class="fsize22">'+res.label+'</div><div class="mg10">'+res.info+'</div></div><div class="coupon-btn"><a  class="" href="'+res.link+'">立即领取</a></div></div></div>';
			}else{
				if(res.show==1){
					html+='<div class="coupon-box"><div class="coupon-center"><div class="coupon-money" style="width: 30px;"></div><div class="coupon-info"><div class="fsize22">'+res.label+'</div><div class="mg10">'+res.info+'</div></div><div class="coupon-btn" style="margin-left: 40px;"><a  class="" href="'+res.link+'">多平台比价</a></div></div></div>';
				}
			}
			if(res.shortUrl){
				$("body").append(res.shortHtml);
				$(res.qcode).qrcode({render: "canvas", width: 160,height: 150,text: res.shortUrl});
			}
			base.removeHtml(res.rwarp);
			base.sleep(500).then(()=>{
				base.addClassHtml(res.warp,html);
			})


		})
	}else if (base.href.indexOf("item.jd") != -1 || base.href.indexOf("item.m.jd") != -1 || base.href.indexOf("//item.yiyaojd.com/") != -1 || base.href.indexOf("//e.jd.com/") != -1 || base.href.indexOf("//pro.jd.com/") != -1 || base.href.indexOf("//pro.m.jd.com/") != -1 || base.href.indexOf("//story.m.jd.com/") != -1 || base.href.indexOf("//prodev.m.jd.com/") != -1 || base.href.indexOf("//prodev.jd.com/") != -1) {
        if (!base.getParam('utm_campaign')) {
			$.getJSON(base.tpi+'?type=jditem&url='+encodeURIComponent(base.href), function(res) {
				if(res.data) window.location.href =res.data;
			})
		}
		$.getJSON(base.api+'?type=jditem&url='+encodeURIComponent(base.href), function(res) {
			let html='';
			if(res.status==1){
				 html+='<div class="coupon-box"><div class="coupon-center"><div class="coupon-money" style="width: 100px;"><div></div><div class="fsize30">'+res.money+'</div></div><div class="coupon-info"><div class="fsize22">'+res.label+'</div><div class="mg10">'+res.info+'</div></div><div class="coupon-btn"><a  class="" href="'+res.link+'">立即领取</a></div></div></div>';
			}else{
				if(res.show==1){
					html+='<div class="coupon-box"><div class="coupon-center"><div class="coupon-money" style="width: 30px;"></div><div class="coupon-info"><div class="fsize22">'+res.label+'</div><div class="mg10">'+res.info+'</div></div><div class="coupon-btn" style="margin-left: 40px;"><a  class="" href="'+res.link+'">平台比价</a></div></div></div>';
				}
			}
			if(res.shortUrl){
				$("body").append(res.shortHtml);
				$(res.qcode).qrcode({render: "canvas", width: 160,height: 150,text: res.shortUrl});
			}
			base.removeHtml(res.rwarp);
			if($('div').is(res.warp)){
				$(res.warp).after(html);
			}else{
				$('.summary-top').after(html);
			}

        })
	}else if (base.href.indexOf("jingfen.jd") != -1){
		 $.getJSON(base.api+'?type=jingfen&url='+encodeURIComponent(base.href), function(res) {
			base.sleep(500).then(()=>{
				base.removeHtml(res.rwarp);
				$(res.warp).append(res.shortHtml);
				$(res.qcode).qrcode({render: "canvas", width: 160,height: 150,text: res.shortUrl});
			})
		 })
	}else if (base.href.indexOf("jd") != -1 || base.href.indexOf("m.jd") != -1){
		setInterval(base.search, 300);
	}

})();