[自动查券助手💸]可查淘宝、天猫、天猫国际、阿里大药房、京东、京东国际、京东大药房等隐藏优惠券。简洁无广告,不花冤枉钱

浏览商品时,自动查询商品是否有隐藏优惠券,支持:京东(jd.com)、淘宝(taobao.com)、天猫(tmall.com)、天猫超市(chaoshi.tmall.com)、天猫国际(tmall.hk)、京东国际(jd.hk)、京东图书、京东大药房(yiyaojd.com)、阿里大药房(maiyao.liangxinyao.com)等,低侵入提示,低调使用,长期维护更新~

目前為 2022-07-11 提交的版本,檢視 最新版本

在您安裝前,Greasy Fork希望您了解本腳本包含“負面功能”,可能幫助腳本的作者獲利,而不能給你帶來任何收益。

作者從這份腳本獲得佣金, 例如透過重寫連結或提供優惠券代碼以加入推薦或附屬代碼 腳本的作者解釋: 【应GreasyFork代码规范要求:优惠券查询功能必须添加此提示!脚本使用过程中无任何强制行为,请大家放心...】

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         [自动查券助手💸]可查淘宝、天猫、天猫国际、阿里大药房、京东、京东国际、京东大药房等隐藏优惠券。简洁无广告,不花冤枉钱
// @description  浏览商品时,自动查询商品是否有隐藏优惠券,支持:京东(jd.com)、淘宝(taobao.com)、天猫(tmall.com)、天猫超市(chaoshi.tmall.com)、天猫国际(tmall.hk)、京东国际(jd.hk)、京东图书、京东大药房(yiyaojd.com)、阿里大药房(maiyao.liangxinyao.com)等,低侵入提示,低调使用,长期维护更新~
// @icon		 data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEAAAABACAYAAACqaXHeAAAFxklEQVR4Xu2be6gUVRzHv799nLEHJfYivTtrj+vMerMXUvaCrCA0KCuSpAdaiYUaWCEVQkpkYA9CeyGG0oOSoCcZGKhoUmYWBrfdVbG7s1cTLEgCc8/cnV/M3gfX6+7OnN3x7syt+ff8zvl9f5/5nXN2zvkt4T/+UH/8OV0sBjALwOV1mHQRaKNhleaNFG4VAFk9uZJAC/0GxcCyjCWX+rUPsx1lx48aT47zm6pIjsUuyHQd61LtFzZ72ptOXlFm+klZGGOGWZSfK/cLWQf6cSxOPT2e7ALROSramPjVTMF+UqVPGG0ra0A+pS1yA1IUuNO05FWKfUJnPrALdLYlr45TbC7gXHScSqIba6keCevAAIBqQebHC5Md/AxgVLV2hzFrYlF+FLrXqiCoLoDe6SG+Y8KU6mPya6ZlL1LwFzpTTwA5XXsL4EerKSfG90ZRXhO6qBQEeQLI68kHGPSuwphhNf0LwDbTkrcPFugJYP8Fp50ny/ahsEalqouATsOSl/T38wTgGubSYjcYl6o6C6094X6zID9w9fkDkEpuRp3tMLSB1hA2+FvGH4C0uA+M96MWaM3fL4M+5nwB6GzDmERM7GfgzBEBgfkhs2iv9T0FKutASmwAYdpIAFB2qL2ju7RPDUBaLAHj+REA4KBpyXFKu0DvTjBqKtjZFHUABKw3LHmvMoDNQOJ8PXkAoHOjDIGIFhiF0hvKAPp+D3wKxowoAygTX9lRsN0PvMrjaxfoN86mtaeI+aUIAzhiWnL0YP2KABLXEse2RxjAl8rfAkODzaVFAQw9khCIFp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I6ILhO3w2mJW9TGTtwAK7zvRdD67GTy4nJFWMA2E+E3SA8W+uOTkV0Pq3Nd6cRgAsBKruJR4TlRqFU646i9rap4ngk2v4L+LTwUPWENukAAAAASUVORK5CYII=
// @namespace    coupon_honghaoer
// @version      2.0.3
// @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/*
// @exclude      *://login.taobao.com/*
// @exclude      *://uland.taobao.com/*
// @exclude      *://pages.tmall.com/*
// @require      https://lf26-cdn-tos.bytecdntp.com/cdn/expire-1-M/jquery/3.2.1/jquery.min.js
// @connect      j.jiayoushichang.com
// @grant        GM_info
// @grant        GM_openInTab
// @grant        GM_getValue
// @grant        GM_setValue
// @grant        GM_xmlhttpRequest
// @run-at       document-idle
// @charset		 UTF-8
// @license      AGPL License
// @antifeature  referral-link 【应GreasyFork代码规范要求:优惠券查询功能必须添加此提示!脚本使用过程中无任何强制行为,请大家放心...】
// @original-script https://greasyfork.org/zh-CN/scripts/398195
// @original-author 匆匆过客
// @original-license GPLA License
// ==/UserScript==

(function() {
	'use strict';
	const host = window.location.host;
	const href = window.location.href;
	const isDebug = false;
	
	/**
	 * 公共功能
	 */
	function commonFunctionObject(){
		this.selectParamterQueryUrl = function(text, tag) { //查询GET请求url中的参数
			if(text.indexOf("?")!=-1){ //选取?后面的字符串,兼容window.location.search,前面的?不能去掉
				var textArray = text.split("?");
				text = "?"+textArray[textArray.length-1];
			}
			var t = new RegExp("(^|&)" + tag + "=([^&]*)(&|$)");
			var a = text.substr(1).match(t);
			if (a != null){
				return a[2];
			}
			return "";
		};
		this.getEndHtmlIdByUrl = function(url) { //获得以html结束的ID
			if(url.indexOf("?")!=-1){
				url = url.split("?")[0]
			}
			if(url.indexOf("#")!=-1){
				url = url.split("#")[0]
			}
			var splitText = url.split("/");
			var idText = splitText[splitText.length-1];
			idText = idText.replace(".html","");
			return idText;
		};
		this.filterStr = function(str){ //去掉空格等
			if(!str) return "";
			str = str.replace(/\t/g,"");
			str = str.replace(/\r/g,"");
			str = str.replace(/\n/g,"");
			str = str.replace(/\+/g,"%2B");//"+"
			str = str.replace(/\&/g,"%26");//"&"
			str = str.replace(/\#/g,"%23");//"#"
			return encodeURIComponent(str)
		};
	}
	const commonFuncObject = new commonFunctionObject();
	
	
	function searchPageObject(){
		this.intervalIsRunComplete = true;  //定时任务一个循环是否完成
		
		/**
		 * 收集列表的元素
		 */
		this.pickupSearchElements = function(){
			var selectorElementList = new Array();
			var url = location.href;
			if(url.indexOf("://s.taobao.com/search")!=-1 || url.indexOf("://s.taobao.com/list")!=-1) { //淘宝搜索页面
				selectorElementList.push({"element":".items >.item", "page":"taobao"});
			}else if(url.indexOf("taobao.com/category")!=-1){ //淘宝店铺分类
				selectorElementList.push({"element":"dl.item", "page":"taobao_category"});
			}else if(url.indexOf("taobao.com/search.htm")!=-1){ //淘宝店铺搜索
				selectorElementList.push({"element":"dl.item", "page":"taobao_shop_search"});
			}
			else if (url.indexOf("://list.tmall.com/search_product.htm")!=-1 || url.indexOf("://list.tmall.com//search_product.htm")!=-1
				|| url.indexOf("://list.tmall.com/coudan/search_product.htm")!=-1) { //天猫、天猫超市
				selectorElementList.push({"element":".product", "page":"tmall_search"});  //天猫
				selectorElementList.push({"element":".product", "page":"tmall_chaoshi"}); //天猫超市
			}else if (url.indexOf("//list.tmall.hk/search_product")!=-1) { //天猫国际
				selectorElementList.push({"element":"#J_ItemList .product", "page":"tmall_hk"});
			}else if(url.indexOf("tmall.com/category-")!=-1){ //天猫分类
				selectorElementList.push({"element":"#J_ShopSearchResult dl.item", "page":"tmall_category"});
			}else if(url.indexOf("tmall.com/category-")!=-1){ //天猫旗舰店分类
				selectorElementList.push({"element":"#J_ShopSearchResult dl.item", "page":"tmall_category"});
			}else if(url.indexOf(".tmall.com/shop/view_shop.htm")!=-1){ //天猫旗舰全部展示
				selectorElementList.push({"element":"dl.item", "page":"tmall_shop_01"});
			}else if(url.indexOf(".tmall.com/search.htm")!=-1){
				selectorElementList.push({"element":"dl.item", "page":"tmall_shop_search"});
			}
			else if(url.indexOf("//maiyao.liangxinyao.com/shop/view_shop.htm")!=-1 
				|| url.indexOf("//maiyao.liangxinyao.com/search.htm")!=-1
				|| url.indexOf("//maiyao.liangxinyao.com/category")!=-1){ //阿里大药房
				selectorElementList.push({"element":"#J_ShopSearchResult dl.item", "page":"ali_yao"});
			}
			else if (url.indexOf("//search.jd.com/Search")!=-1) { //京东搜索
				selectorElementList.push({"element":"#J_goodsList li.gl-item", "page":"jd"});
			}else if(url.indexOf("//search.jd.hk/Search")!=-1){ //京东国际
				selectorElementList.push({"element":"#plist li.gl-item", "page":"jd_hk"});
			}else if(url.indexOf("//mall.jd.com/view_search")!=-1){ //京东大药房
				selectorElementList.push({"element":"li.jSubObject", "page":"jd_yao"});
			}
			return selectorElementList;
		};
		
		/**
		 * 分析链接,提取id和平台信息
		 * @param {Object} url
		 * @param {Object} tag
		 */
		this.analysisUrl = function(url, tag){
			if(!!url){
				var id = commonFuncObject.selectParamterQueryUrl(url, tag);
				if(!!id){
					var platform = "taobao";
					if(url.indexOf("jd.com")!=-1 || url.indexOf("yiyaojd.com")!=-1){
						platform = "jd";
					}else if(url.indexOf("taobao.com")!=-1 || url.indexOf("maiyao.liangxinyao.com")!=-1){
						platform = "taobao";
					}else if(url.indexOf("tmall.com")!=-1 || url.indexOf("tmall.hk")!=-1){
						platform = "tmall";
					}
					return {"id":id, "platform":platform};
				}
			}
			return null;
		};
		
		/**
		 * 为所有的商品创建提示
		 * @param {Object} elementData
		 */
		this.createAllElementHtml = function(elementData){
			let that = this;
			$(elementData.element).each(function(){  //遍历所有的商品框
				that.createOneElementHtml($(this), elementData);
			});
			that.intervalIsRunComplete = true;
		};
		
		/**
		 * 为商品box添加有券提醒
		 * @param {Object} $element  每一个商品box
		 * @param {Object} elementData id and page
		 */
		this.createOneElementHtml = function($element, elementData){  //查询到每个商品list
			if($element.attr("completebox")){  //当存在时,说明已经处理过了
				return;
			}
			
			$element.css("position","relative");
			var page = elementData.page;
			var goodsDetailUrl = null;
			
			if(page==="taobao"){
				goodsDetailUrl = $element.find("a[id^='J_Itemlist_TLink_']").attr("href");
			}else if(page==="taobao_category"){
				goodsDetailUrl = $element.find(".J_TGoldData").attr("href");
			}else if(page==="taobao_shop_search"){
				goodsDetailUrl = $element.find(".J_TGoldData").attr("href");
			}
			else if(page==="ali_yao"){
				goodsDetailUrl = $element.find(".J_TGoldData").attr("href");
			}
			else if(page==="tmall_search"){
				goodsDetailUrl = $element.find("a.productImg").attr("href");
			}else if(page==="tmall_hk"){
				goodsDetailUrl = $element.find("a.productImg").attr("href");
			}else if(page==="tmall_chaoshi"){
				goodsDetailUrl = $element.find("div.product-img").find("a").attr("href");
			}else if(page==="tmall_category"){
				goodsDetailUrl = $element.find(".J_TGoldData").attr("href");
			}else if(page==="tmall_shop_01"){
				goodsDetailUrl = $element.find("dt.photo").find("a").attr("href");
			}else if(page==="tmall_shop_search"){
				goodsDetailUrl = $element.find(".J_TGoldData").attr("href");
			}
			else if(page==="jd"){
				goodsDetailUrl = $element.find("div.p-img").find("a").attr("href");
			}else if(page==="jd_hk"){
				goodsDetailUrl = $element.find("div.p-img").find("a").attr("href");
			}else if(page==="jd_yao"){
				goodsDetailUrl = $element.find("div.jPic").find("a").attr("href");
			}
			
			if(!goodsDetailUrl){
				return;
			}
			if(isDebug) console.log(goodsDetailUrl);
			
			var analysisData = null;
			if(page==="jd" || page==="jd_hk"){
				var jdId = commonFuncObject.getEndHtmlIdByUrl(goodsDetailUrl);
				if(!!jdId) analysisData = {"id":jdId, "platform":"jd"};
			}else{
				analysisData = this.analysisUrl(goodsDetailUrl, "id");
			}
			if(!!analysisData){ //一切数据校验完毕,此处查询是否有券
				let requestUrl = "http://j.jiayoushichang.com/api/ebusiness/coupon/exist/"+analysisData.platform+"?id="+analysisData.id;
				GM_xmlhttpRequest({
					url: requestUrl,
					method: "GET",
					headers: {"Content-Type": "application/x-www-form-urlencoded"},
					onload: function(response) {
						var status = response.status;
						if(status==200||status=='200'){
							var responseText = response.responseText;
							if(!!responseText){
								try{
									var serverResponseJson = JSON.parse(responseText);
									var tip = serverResponseJson.tip;
									if(!!tip){
										$element.append(tip);
									}
								}catch(e){}
							}
						}
					}
				});
			}
			$element.attr("completebox","true");
		};
		
		/**
		 * 开始查询
		 */
		this.startQueryList = function(){
			let selectorElementList = this.pickupSearchElements();
			let that = this;
			setInterval(()=>{
				if(that.intervalIsRunComplete){
					selectorElementList.forEach((elementData)=>{
						if(!!elementData){
							this.createAllElementHtml(elementData);
						}
					});
				}
			}, 400);
		};
	};
	try{
		(new searchPageObject()).startQueryList();
	}catch(e){}
	
	/**
	 * 详情页领券,查券功能
	 */
	function queryCoupon(){
		this.isRun = function(){
			var urls=["detail.tmall.com", "detail.tmall.hk", "item.taobao.com", "chaoshi.detail.tmall.com", "item.jd.com", "item.yiyaojd.com", "npcitem.jd.hk"];
			for(var i=0; i<urls.length;i++){
				if(window.location.host.indexOf(urls[i])!=-1){
					return true;
				}
			}
			return false;
		}
		this.getPlatform = function(){
			let host = window.location.host;
			let platform = "";
			if(host.indexOf("detail.tmall")!=-1){
				platform = "tmall";
			}else if(host.indexOf("item.taobao.com")!=-1){
				platform = "taobao";
			}else if(host.indexOf("item.jd.com")!=-1 || host.indexOf("item.yiyaojd.com")!=-1 || host.indexOf("npcitem.jd.hk")!=-1){
				platform = "jd";
			}
			return platform;
		};
		this.getGoodsData = function(platform){
			var goodsId = "";
			var goodsName = "";
			var href = window.location.href;
			if(platform=="taobao"){
				goodsId =  commonFuncObject.selectParamterQueryUrl(window.location.search, "id");
				goodsName=$(".tb-main-title").text();
	
			}else if(platform=="tmall"){
				goodsId =  commonFuncObject.selectParamterQueryUrl(window.location.search, "id");
				goodsName=$(".tb-detail-hd").text();
	
			}else if(platform=="jd"){
				goodsName=$("div.sku-name").text();
				goodsId = commonFuncObject.getEndHtmlIdByUrl(href);
	
			}
			var data={"goodsId":goodsId, "goodsName":commonFuncObject.filterStr(goodsName)}
			return data;
		};
		this.request = function(mothed, url, param){
			return new Promise(function(resolve, reject){
				GM_xmlhttpRequest({
					url: url,
					method: mothed,
					data:param,
					onload: function(response) {
						var status = response.status;
						var playurl = "";
						if(status==200||status=='200'){
							var responseText = response.responseText;
							resolve({"result":"success", "json":responseText});
						}else{
							reject({"result":"error", "json":null});
						}
					}
				});
			})
		};
		this.createCouponHtml = function(platform, goodsId, goodsName){
			if(!platform || !goodsId) return;
			
			var goodsCouponUrl = "http://j.jiayoushichang.com/api/ebusiness/find?n=7&v=1.0.2&p="+platform+"&i="+goodsId+"&q="+goodsName;
			var goodsPrivateUrl = "http://j.jiayoushichang.com/api/private/change/coupon?script=7&platform="+platform+"&id=";

			this.request("GET", goodsCouponUrl, null).then((resutData)=>{
				if(resutData.result==="success" && !!resutData.json){
					var data = JSON.parse(resutData.json).data;
					if(!data || data==="null" || !data.css || !data.html || !data.handler){
						return;
					}
					var cssText = data.css;
					var htmlText = data.html;
					var handler = data.handler;
					var templateId = data.templateId;
					$("body").prepend("<style>"+cssText+"</style>");
					
					console.log("handler",handler);
					console.log("htmlText",htmlText);

					var handlers = handler.split("@");
					for(var i=0; i<handlers.length; i++){
						var $handler = $(""+handlers[i]+"");
						if(platform=="taobao"){
							$handler.parent().after(htmlText);
						}else if(platform=="tmall"){
							$handler.parent().after(htmlText);
						}else if(platform=="jd"){
							$handler.after(htmlText);
						}
					}
					
					var $llkk = $("#"+templateId);
					if($llkk.length != 0){
						//可点击的情况下执行
						let couponElementA = $llkk.find("a[name='cpShUrl']");
						couponElementA.unbind("click").bind("click", ()=>{
							event.stopPropagation();
							event.preventDefault();
							let couponId = $llkk.data("id");
							if(!!couponId){
								this.request("GET", goodsPrivateUrl+couponId, null).then((resutData2)=>{
									if(resutData2.result==="success" && !!resutData2.json){
										let url = JSON.parse(resutData2.json).url;
										if(!!url) GM_openInTab(url, {active:true});
									}
								});
							}
						});
						
						setInterval(()=>{
							$llkk.find("*").each(function(){
								$(this).removeAttr("data-spm-anchor-id")
							});
						},100);
						
						//canvas画二维码
						var $canvasElement = $("#ca"+templateId);
						if($canvasElement.length != 0){
							let couponId = $llkk.data("id");
							this.request("GET", goodsPrivateUrl+couponId, null).then((resutData2)=>{
								if(resutData2.result==="success" && !!resutData2.json){
									let img = JSON.parse(resutData2.json).img;
									if(!!img){
										var canvasElement = document.getElementById("ca"+templateId);
										var cxt = canvasElement.getContext("2d");
										var imgData = new Image();
										imgData.src = img;
										imgData.onload=function(){
											cxt.drawImage(imgData, 0, 0, imgData.width, imgData.height);
										}
									}
								}
							});
						}
						
					}
				}
			});
		};
		this.start = function(){
			if(this.isRun()){				
				var platform = this.getPlatform();
				if(!!platform){
					var goodsData = this.getGoodsData(platform);
					this.createCouponHtml(platform, goodsData.goodsId, goodsData.goodsName);
				}
			}
		};
	}
	
	try{
		(new queryCoupon()).start();
	}catch(e){}
})();