[🔥]!!網購小助手,不花冤枉錢:自動查詢淘寶、天貓、天貓國際、京東、京東國際、唯品會等隱藏的大額優惠券,有無優惠券一目瞭然,持續維護更新,請放心使用!

網購小助手功能有:🔥1、瀏覽商品時指令碼或直譯式程式會自動查詢商品是否有隱藏的優惠券,支援:京東、淘寶、天貓、天貓超市、天貓國際、京東國際、京東圖書、京東大藥房、阿里大藥房、唯品会等;🔥2、商品二維碼生成,手機可快捷訪問該商品;🔥3、瀏覽記錄標註,避免反覆瀏覽相同商品(本地存儲,可手動清空,快捷键shift+c清空);🔥4、PC網頁優化,讓使用更加舒適;代碼全部採用低侵入提示,指令碼或直譯式程式長期維護更新~

目前為 2024-02-27 提交的版本,檢視 最新版本

在您安裝前,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              [🔥]!!网购小助手,不花冤枉钱:自动查询淘宝、天猫、天猫国际、京东、京东国际、唯品会等隐藏的大额优惠券,有无优惠券一目了然,持续维护更新,请放心使用!
// @name:zh           [🔥]!!网购小助手,不花冤枉钱:自动查询淘宝、天猫、天猫国际、京东、京东国际、唯品会等隐藏的大额优惠券,有无优惠券一目了然,持续维护更新,请放心使用!
// @name:zh-TW        [🔥]!!網購小助手,不花冤枉錢:自動查詢淘寶、天貓、天貓國際、京東、京東國際、唯品會等隱藏的大額優惠券,有無優惠券一目瞭然,持續維護更新,請放心使用!
// @description       网购小助手功能有:🔥1、浏览商品时脚本会自动查询商品是否有隐藏的优惠券,支持:京东、淘宝、天猫、天猫超市、天猫国际、京东国际、京东图书、京东大药房、阿里大药房、唯品会等;🔥2、商品二维码生成,手机可快捷访问该商品;🔥3、浏览记录标注,避免反复浏览相同商品(本地存储,可手动清空,快捷键shift+c清空);🔥4、PC网页优化,让使用更加舒适;代码全部采用低侵入提示,脚本长期维护更新~
// @description:zh    网购小助手功能有:🔥1、浏览商品时脚本会自动查询商品是否有隐藏的优惠券,支持:京东、淘宝、天猫、天猫超市、天猫国际、京东国际、京东图书、京东大药房、阿里大药房、唯品会等;🔥2、商品二维码生成,手机可快捷访问该商品;🔥3、浏览记录标注,避免反复浏览相同商品(本地存储,可手动清空,快捷键shift+c清空);🔥4、PC网页优化,让使用更加舒适;代码全部采用低侵入提示,脚本长期维护更新~
// @description:zh-TW 網購小助手功能有:🔥1、瀏覽商品時指令碼或直譯式程式會自動查詢商品是否有隱藏的優惠券,支援:京東、淘寶、天貓、天貓超市、天貓國際、京東國際、京東圖書、京東大藥房、阿里大藥房、唯品会等;🔥2、商品二維碼生成,手機可快捷訪問該商品;🔥3、瀏覽記錄標註,避免反覆瀏覽相同商品(本地存儲,可手動清空,快捷键shift+c清空);🔥4、PC網頁優化,讓使用更加舒適;代碼全部採用低侵入提示,指令碼或直譯式程式長期維護更新~
// @icon		      data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAIAAAACACAYAAADDPmHLAAAAAXNSR0IArs4c6QAACetJREFUeF7tnb1uFUcUx2exRKQoSInSQZAobCpqKDFPQZO8QcwbIPADJEXIGyQFNDwCNiU0NKSxb5dA4SgKkhMUTOwbnb2Z67nrmZ0zH+fMmfW4AfvO7nz8f+djPu5upyb68+v6+iZ07YK6sNmp+W2zm3Ol+s+GP51Su/pvc9U91/8/USe7V2ez5WdTGrJuCp0BsbXQLnFz9RMgATimAkWVAIDga6p7AKJSC+4Dp3YgqgFAkujjUHTbNXkH0QBwunafpcd93m1fme09jLuW5yqRAGhrL+3e80kgFwRRAExP+DPzjG34iySvIAKA6QsvF4TiALxd39iZjqsPDRrlQ0MxAN6sX3+o1LyfyrWfciCwA3D+3D0e7xM1v8O94sgKQLN6DAy83oANgPMd6zHCm2X4ICAHYLGY0+2EDkErDyNADwIpAM3l58CYFgIyAJr4OcTX96CDgASAFu9zik8LQXYAmvgU4i/uCVvPl2f7d3LWkBWAJn5Oaez3yg1BNgCa+PTiL4NBRk+QBYAmPp/4uSFIBqBl+/zi54QgCYDaxP/k1i118dZNdfHmzX4M4Xfz58OLF/2vRy9f9v8e/vConLromtOmiNEA1CI+iPzZ1rdnxMaO7+GjBQSyYYiHIAqAGsS/dG9LXdrawuqMKgcwSAUhdicxEoCNOWrEChQCi//y559Ia5YKwpXZfrCewRdItf5UVx9KjEQIYtYIggCQLH6s1UPiN0wGQ2D44+tvlE4eQ66jKxuWD6ABkLqtG+LyQai/Hv3Yj71LNHOmgAVDGgQh+QAagDfr8uI+NtEDd3304mWUpWLrkARBSChAASDR9WOEASsHYXL8YOqTBAH2MAkSAHnWf3l/b1RXCjF8EOQELge0mFmBFwCJ1g+DMwYAhfhaEF/O8Xbjeg7tstwDEwpGAZAqvgsAneRRZ+UuCCRODX0JYbUADN1xCfcLU089UyhRP8ZN+LyAEwDJ1m92HECIzfAxA+grYw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AM7AC03sDri/qGNnMLruooB0EDov5e3e3m2f6eE8GIAOM0N4H+0j6stOdBm3aXcffEk0CfAYqYwXRAkCS/KA9jAmNK0UaLw4gGoPUcA0eeqe36iTna5M3ufpx2Eo5Di5coupo8XNiXnCSA6jFCJ6VysMsVnATEN1zB0an6b6gHX2HbVKHqVHmBMEE4ganHtAQBji9ZV7jRkLNoN3kL3wOU1tDWfllvEcPhdchxPUeY/DpXYaLj0y1IAAAAASUVORK5CYII=
// @namespace         coupon_honghaoer
// @version           2.1.11
// @author            洪皓儿
// @match             *://*.taobao.com/*
// @match             *://*.tmall.com/*
// @match             *://chaoshi.detail.tmall.com/*
// @match             *://pages.tmall.com/wow/an/cs/search**
// @match             *://*.tmall.hk/*
// @match             *://*.liangxinyao.com/*
// @match             *://*.jd.com/*
// @match             *://*.jd.hk/*
// @match             *://*.yiyaojd.com/*
// @match             *://detail.vip.com/detail-*
// @match             *://www.vipglobal.hk/detail-*
// @match             *://category.vip.com/suggest.php**
// @match             *://list.vip.com/*.html
// @exclude           *://login.taobao.com/*
// @exclude           *://uland.taobao.com/*
// @exclude           *://www.taobao.com/*
// @exclude           *://map.taobao.com/*
// @exclude           *://jingfen.jd.com/*
// @require           https://lf26-cdn-tos.bytecdntp.com/cdn/expire-1-M/jquery/3.2.1/jquery.min.js
// @require           https://lf9-cdn-tos.bytecdntp.com/cdn/expire-1-M/jquery.qrcode/1.0/jquery.qrcode.min.js
// @require           https://lf3-cdn-tos.bytecdntp.com/cdn/expire-1-M/keypress/2.1.5/keypress.min.js
// @connect           api.shuoaini.xyz
// @grant             GM_openInTab
// @grant             GM.openInTab
// @grant             GM_getValue
// @grant             GM.getValue
// @grant             GM_setValue
// @grant             GM.setValue
// @grant             GM_xmlhttpRequest
// @grant             GM.xmlHttpRequest
// @grant             GM_registerMenuCommand
// @license           AGPL License
// @antifeature  	  referral-link 【此提示为GreasyFork代码规范要求含有查券功能的脚本必须添加,请知悉!】
// @charset		      UTF-8
// @run-at            document-idle
// @original-script   https://greasyfork.org/zh-CN/scripts/469417
// @original-author   huahuacat
// @original-license  AGPL License
// ==/UserScript==

(function() {
	'use strict';
	
	/**
	 * 代码版权说明:
	 * 原作者huahuacat,本脚本在原作者基础上优化了代码结构,添加了新功能
	 * 本脚本代码已获得原作者授权,并遵循AGPL License开源协议,请悉知!
	 */
	
	const recordBrowsingHistoryKey = "record_browsing_history_key";
	const browsedHtml= `
		<div style="position:absolute;white-space: nowrap; top:7px;padding:2px 5px;font-size:12px;background-color:rgba(0,0,0);color:#FFF;z-index:9999999999;border-radius:20px;left:10px;"><b>已浏览</b></div>
	`
	
	/**
	 * 公共的方法
	 */
	class CommonTools{
		request(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({"code":"success", "result":responseText});
						}else{
							reject({"code":"error", "result":null});
						}
					}
				});
			})
		}
		randomNumber(){
			return Math.ceil(Math.random()*100000000);
		}
		getPlatform(url = window.location.href){
			let platform = "";
			if(url.indexOf("detail.tmall")!=-1 || url.indexOf("tmall.hk")!=-1 || url.indexOf("pages.tmall.com")!=-1){
				platform = "tmall";
			}else if(url.indexOf("taobao.com")!=-1 || url.indexOf("maiyao.liangxinyao.com")!=-1){
				platform = "taobao";
			}else if(url.indexOf("jd.com")!=-1 || url.indexOf("npcitem.jd.hk")!=-1 || url.indexOf("yiyaojd.com")!=-1){
				platform = "jd";
			}else if(url.indexOf("detail.vip.com")!=-1 || url.indexOf("www.vipglobal.hk")!=-1){
				platform = "vpinhui";
			}
			return platform;
		}
		getParamterQueryUrl(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 "";
		}
		getEndHtmlIdByUrl(url){
			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;
		}
		getElementAsync(selector, allowEmpty = true, delay=10, maxDelay = 2000){
			return new Promise((resolve,reject) =>{
				let totalDelay = 0;
				let element = document.querySelector(selector);
				let result = allowEmpty ? !!element : (!!element && !!element.innerHTML);
				if(result){
					resolve(element);
				}
				let elementInterval = setInterval(()=>{
					if(totalDelay >= maxDelay){ //总共检查2s,如果还是没找到,则返回
						resolve(null);
						clearInterval(elementInterval);
					}
					element = document.querySelector(selector);
					result = allowEmpty ? !!element : (!!element && !!element.innerHTML);
					if(result){
						clearInterval(elementInterval);
						resolve(element);
					}else{
						totalDelay += delay;
					}
				}, delay);
			});
		}
		GMgetValue(name, value=null) {
			let storageValue = value;
			if (typeof GM_getValue === "function") {
				storageValue = GM_getValue(name, value);
			} else if(typeof GM.setValue === "function"){
				storageValue = GM.getValue(name, value);
			}else{
				var arr = window.localStorage.getItem(name);
				if(arr != null){
					storageValue = arr
				}
			}
			return storageValue;
		}
		GMsetValue(name, value){
			if (typeof GM_setValue === "function") {
				GM_setValue(name, value);
			} else if(typeof GM.setValue === "function"){
				GM.setValue(name, value);
			}else{
				window.localStorage.setItem(name, value)
			}
		}
	}
	
	/**
	 * 优惠券相关功能
	 */
	class Coupon{
		platforms = ["detail.tmall.com", "item.taobao.com", "item.jd.com", "item.yiyaojd.com", "npcitem.jd.hk", 
			"detail.tmall.hk", "detail.vip.com", "www.vipglobal.hk"];
		constructor(){
			this.commonTools = new CommonTools();
		}
		isRun(){
			for(var i=0; i<this.platforms.length;i++){
				if(window.location.host.indexOf(this.platforms[i])!=-1){
					return true;
				}
			}
			return false;
		}
		filterName(str){
			if(!str) return "";
			str = str.replace(/\t/g,"");
			str = str.replace(/\r/g,"");
			return encodeURIComponent(str)
		}
		async getGoodsData(platform){
			var goodsId = "";
			var goodsName = "";
			const href = window.location.href;
			if(platform=="taobao"){
				goodsId = this.commonTools.getParamterQueryUrl(window.location.search, "id");
				try{
					let titleObj = document.querySelector(".tb-main-title");
					if(!titleObj){
						titleObj = await this.commonTools.getElementAsync("[class^='ItemHeader--mainTitle--']", false, 10, 500);
					}
					if(!!titleObj){
						goodsName = titleObj.textContent;
					}
				}catch(e){}
				
			}else if(platform=="tmall"){
				goodsId = this.commonTools.getParamterQueryUrl(window.location.search, "id");
				try{
					const titleObj = await this.commonTools.getElementAsync("[class^='ItemHeader--mainTitle--']", false, 10, 500);
					if(!!titleObj){
						goodsName = titleObj.textContent;
					}
				}catch(e){}
				
			}else if(platform=="jd"){
				goodsId = this.commonTools.getEndHtmlIdByUrl(href);
				try{
					const titleObj = await this.commonTools.getElementAsync("[class='sku-name']", false, 10, 500);
					if(!!titleObj){
						goodsName = titleObj.textContent;
					}
				}catch(e){}
			}else if(platform=="vpinhui"){
				goodsId = this.commonTools.getEndHtmlIdByUrl(href).replace("detail-","");
				const titleObj = await this.commonTools.getElementAsync("[class='pib-title-detail']", false, 10, 500);
				if(!!titleObj){
					goodsName = titleObj.textContent;
				}
			}
			const data = {"goodsId":goodsId, "goodsName":this.filterName(goodsName)};
			return data;
		}
		randomSpmValue(){
			$("meta[name='data-spm']").each(function(){
				var max = 5000;
				var min = 1000;
				var randomValue = Math.floor(Math.random() * (max - min + 1) ) + min;
				var randomLetter = String.fromCharCode(Math.floor( Math.random() * 26) + "a".charCodeAt(0));
				$(this).attr("content", randomValue+randomLetter);
			});
			$("meta[name='spm-id']").each(function(){
				var max = 5000;
				var min = 1000;
				var randomValue = Math.floor(Math.random() * (max - min + 1) ) + min;
				var randomLetter = String.fromCharCode(Math.floor( Math.random() * 26) + "a".charCodeAt(0));
				$(this).attr("content", randomValue+randomLetter);
			});
			$("body").find("*").each(function(){
				$(this).removeAttr("data-spm-anchor-id");
				$(this).removeAttr("data-spm");
			});
		}
		runAliDeceptionSpm(){
			const host = window.location.host;
			if(host.indexOf("aliyun.com")!=-1 || host.indexOf("taobao.com")!=-1 || host.indexOf("tmall.com")!=-1){
				this.randomSpmValue();
				setInterval(()=>{
					this.randomSpmValue();
				}, 2000);
			}
		}
		recordBrowsingHistory(content){
			return new Promise((resolve, reject)=>{
				let histories = this.commonTools.GMgetValue(recordBrowsingHistoryKey,[]);
				if(!histories.includes(content)){
					histories.unshift(content);
					this.commonTools.GMsetValue(recordBrowsingHistoryKey,histories.slice(0,60));
				}
				resolve(true);
			})
		}
		async createHtml(platform, goodsId, goodsName){
			if(!platform || !goodsId){
				return "kong";
			}
			//把浏览记录给存在本地
			this.recordBrowsingHistory(platform+"_"+goodsId);
			let addition = "";
			if(platform=="vpinhui"){
				const vip = goodsId.split("-");
				addition = vip[0];
				goodsId = vip[1];
			}
			const goodsCouponUrl = "http://api.shuoaini.xyz/api/coupon/query?no=888&version=1.0.2&platform="+platform+"&id="+goodsId+"&q="+goodsName+"&addition="+addition;
			try{
				const data = await this.commonTools.request("GET", goodsCouponUrl, null);
				if(data.code=="success" && !!data.result){
					const json = JSON.parse(data.result);
					this.createCoupon(platform, json.data);
					this.createQrcode(platform, json.mscan);
				}
			}catch(e){
				console.log("createCouponHtml:",e);
			}
		}
		async createCoupon(platform, result){
			if(!result || result==="null" || !result.hasOwnProperty("css") || !result.hasOwnProperty("html") || !result.hasOwnProperty("handler")){
				return;
			}
			const  cssText = result.css, htmlText = result.html, handler = result.handler, templateId = result.templateId;
			if(!cssText || !htmlText || !handler){
				return;
			}
			$("body").prepend("<style>"+cssText+"</style>");
			
			// 添加HTML
			const 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);
				}else if(platform=="vpinhui"){
					$handler.after(htmlText);
				}
			}
			
			const $template = $("#"+templateId);
			if($template.length == 0){
				return;
			}
			
			const couponId = $template.data("id");
			const goodsPrivateUrl = "http://api.shuoaini.xyz/api/private/real?no=888&v=1.0.2&p="+platform+"&id=";
			
			if(!/\d/.test(couponId)){
				return;
			}
			
			setInterval(()=>{
				$template.find("*").each(function(){
					$(this).removeAttr("data-spm-anchor-id");
				});
			},400);
			
			const couponElementA = $template.find("a[name='cpShUrl']");				
			couponElementA.unbind("click").bind("click", ()=>{
				event.stopPropagation();
				event.preventDefault();
				this.commonTools.request("GET", goodsPrivateUrl+couponId, null).then((privateResultData)=>{
					if(privateResultData.code==="success" && !!privateResultData.result){
						let url = JSON.parse(privateResultData.result).url;
						if(!!url) GM_openInTab(url, {active:true});
					}
				});
			});
								
			//canvas画二维码
			var $canvasElement = $("#ca"+templateId);
			if($canvasElement.length == 0){
				return;
			}
			const qrcodeResultData = await this.commonTools.request("GET", goodsPrivateUrl+couponId, null);
			if(!!qrcodeResultData && qrcodeResultData.code==="success" && !!qrcodeResultData.result){
				let img = JSON.parse(qrcodeResultData.result).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);
					}
				}
			}
		}
		async createQrcode(platform, mscan){
			if(!mscan || mscan==="null" || !mscan.hasOwnProperty("mount") 
				|| !mscan.hasOwnProperty("html")|| !mscan.hasOwnProperty("qrcode")){
				return;
			}
			const {mount, html, qrcode, iden} = mscan;
			if(!!mount && !!html && !!qrcode && !!iden){
				$(mount).append(html);
				var canvasElement = document.getElementById("mscan"+iden);
				var width = canvasElement.getAttribute("width");
				var height = canvasElement.getAttribute("height");
				var cxt = canvasElement.getContext("2d");
				var imgData = new Image();
				imgData.src = qrcode;
				imgData.onload=function(){
					cxt.drawImage(imgData, 0, 0, width, height);
				}
			}
		}
		async start(){
			if(this.isRun()){
				this.runAliDeceptionSpm();
				const platform = this.commonTools.getPlatform();
				if(!platform) return;
				//如果sku太多就折叠,不然移动端体验太差了
				if(platform=="tmall" || platform=="taobao"){
					this.commonTools.getElementAsync("[class='skuItemWrapper']", false, 10, 1500).then((skuItemWrapper)=>{
						if(skuItemWrapper != null){
							const { style } = skuItemWrapper;
							style.maxHeight = "350px";
							style.overflow = "auto";
						}
					}).catch(()=>{});
				}
				const goodsData = await this.getGoodsData(platform);
				this.createHtml(platform, goodsData.goodsId, goodsData.goodsName);
			}
		}
	}
	
	class SearchPageObject{
		intervalIsRunComplete = true;  //定时任务一个循环是否完成
		constructor(){
			let commonTools = new CommonTools();
			this.histories = commonTools.GMgetValue(recordBrowsingHistoryKey, []);
			this.commonTools = commonTools;
		}
		pickupSearchElements(){ //收集列表的元素
			const selectorElementList = new Array();
			const url = window.location.href;
			if(url.indexOf("://s.taobao.com/search")!=-1 || url.indexOf("://s.taobao.com/list")!=-1) { //淘宝搜索页面
				selectorElementList.push({"element":".items >.item", "page":"taobao"});
		
		        selectorElementList.push({"element":".Content--content--sgSCZ12 .Card--doubleCardWrapper--L2XFE73", "page":"taobao_new"});
				selectorElementList.push({"element":".Content--content--sgSCZ12 .Card--listCardWrapper--ax09OfT", "page":"taobao_new"});
				selectorElementList.push({"element":".Content--content--sgSCZ12 .Card--doubleCardWrapperMall--uPmo5Bz", "page":"taobao_new"});
				selectorElementList.push({"element":".Content--content--sgSCZ12 .Card--listCardWrapperMall--E3jI8L4", "page":"taobao_new"});
		
			}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
				|| url.indexOf("://pages.tmall.com/wow/an/cs/search")!=-1) { //天猫超市
				selectorElementList.push({"element":".product", "page":"tmall_chaoshi_search"});
				selectorElementList.push({"element":".chaoshi-recommend-list .chaoshi-recommend-item", "page":"tmall_chaoshi_search_new"}); //新天猫超市
				selectorElementList.push({"element":".feeds-list .feeds-item", "page":"tmall_chaoshi_search_20240115"}); //天猫超市新页面https://pages.tmall.com/wow/an/cs/search%2F18a4077f847?spm=a3204.7084713.1996500281.13.z3hXwd&s=0&user_id=725677994&area_code=330100&cat=50514029&active=1&style=g&acm=lb-zebra-27092-331852.1003.4.457104&search_condition=1&sort=s&scm=1003.4.lb-zebra-27092-331852.OTHER_14434954372593_457104&n=40#/?q=%E7%89%99%E8%86%8F&sort=s&page_no=1&spos=&brand=&prop=&cat=50514008
		
			}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 || url.indexOf("//search.jd.com/search")!=-1) { //京东搜索
				selectorElementList.push({"element":"#J_goodsList li.gl-item", "page":"jd_search"});
			}else if(url.indexOf("//search.jd.hk/Search")!=-1){ //京东国际https://search.jd.hk/Search?keyword=ds
				selectorElementList.push({"element":"#plist li.gl-item", "page":"jd_hk_search"}); //可能已弃用
				selectorElementList.push({"element":"li[class^='productList_']", "page":"jd_hk_new_search"});//20240119添加
			}else if(url.indexOf("//mall.jd.com/view_search")!=-1){ //京东大药房
				selectorElementList.push({"element":"li.jSubObject", "page":"jd_yao_search"});
			}else if(url.indexOf("www.jd.com")!=-1 && window.location.pathname=="/"){
				selectorElementList.push({"element":"#feedContent0 li.more2_item_good", "page":"jd_homepage"});
			}
			else if(url.indexOf("category.vip.com/suggest.php")!=-1){
				selectorElementList.push({"element":"#J_searchCatList .c-goods-item", "page":"vpinhui_search_page"});
			}else if(url.indexOf("://list.vip.com")!=-1){
				selectorElementList.push({"element":"#J_wrap_pro_add .c-goods-item", "page":"vpinhui_list"});
			}
			return selectorElementList;
		}
		createAllElementHtml(elementData){ //为所有的商品创建提示
			const self = this;
			$(elementData.element).each(function(){  //遍历所有的商品框
				self.createOneElementHtml($(this), elementData);
			});
			self.intervalIsRunComplete = true;
		}
		
		markBrowsingHistory($element, mark){
			if(this.histories.includes(mark)){
				$element.append(browsedHtml);
			}
		}
		
		/**
		 * 为商品box添加有券提醒
		 * @param {Object} $element  每一个商品box
		 * @param {Object} elementData id and page
		 */
		async createOneElementHtml($element, elementData){  //查询到每个商品list
			if($element.attr("honghaoerbox")){  //当存在时,说明已经处理过了
				return;
			}
			$element.attr("honghaoerbox","true");
			$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_new"){
				let href = $element.attr("href");
				goodsDetailUrl = href.indexOf("http") == -1 ? (location.protocol + href) : 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_chaoshi_search"){
				let href = $element.find("div.product-img").find("a").attr("href");
				goodsDetailUrl = href.indexOf("http") ==-1 ? (location.protocol + href) : href;
			}else if(page==="tmall_chaoshi_search_new"){
				let href = !!$element.attr("href")?$element.attr("href"):$element.find("a").attr("href");
				goodsDetailUrl = href.indexOf("http") ==-1 ? (location.protocol + href) : href;
			}else if(page==="tmall_hk"){
				goodsDetailUrl = $element.find("a.productImg").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=="tmall_chaoshi_search_20240115"){
					goodsDetailUrl = $element.find("a").attr("href");
			}
			else if(page==="jd_search"){
				goodsDetailUrl = $element.find("div.p-img").find("a").attr("href");
			}else if(page==="jd_hk_search"){
				goodsDetailUrl = $element.find("div.p-img").find("a").attr("href");
			}else if(page==="jd_hk_new_search"){
				goodsDetailUrl = $element.find("a").attr("href");
			}else if(page==="jd_yao_search"){
				goodsDetailUrl = $element.find("div.jPic").find("a").attr("href");
			}else if(page=="jd_homepage"){
				goodsDetailUrl = $element.find("a[class='more2_lk']").attr("href");
			}
			else if(page=="vpinhui_search_page"){
				goodsDetailUrl = $element.find("a").attr("href");
			}else if(page=="vpinhui_list"){
				goodsDetailUrl = $element.find("a").attr("href");
			}
			if(!goodsDetailUrl){
				return;
			}
			var analysisData = null;
			if(page.indexOf("jd_")!=-1){
				var jdId = this.commonTools.getEndHtmlIdByUrl(goodsDetailUrl);
				if(!!jdId) analysisData = {"id":jdId, "platform":"jd"};
			}else if(page.indexOf("vpinhui_")!=-1){
				var vipId = this.commonTools.getEndHtmlIdByUrl(goodsDetailUrl).replace("detail-","");;
				if(!!vipId){
					analysisData = {"id":vipId.split("-")[1], "platform":"vpinhui"};
				}
			}else{
				var platform = this.commonTools.getPlatform(goodsDetailUrl);
				var id = this.commonTools.getParamterQueryUrl(goodsDetailUrl, "id");
				if(platform && id){
					analysisData = {"id":id, "platform":platform};
				}
			}
			if(!analysisData){
				return;
			}
			this.markBrowsingHistory($element, analysisData.platform + "_" + analysisData.id);
			
			try{
				const searchUrl = "http://api.shuoaini.xyz/api/ebusiness/q/c?p="+analysisData.platform+"&id="+analysisData.id;
				const data = await this.commonTools.request("GET", searchUrl, null);
				if(data.code=="success" && !!data.result){
					const tip = JSON.parse(data.result).tip;
					if(tip){
						$element.append(tip);
					}
				}
			}catch(e){
				console.log("查券出现异常",e);
			}
		}
		searchPage(selectorElementList){
			if(!this.intervalIsRunComplete){
				return;
			}
			selectorElementList.forEach((elementData)=>{
				if(!!elementData){
					this.createAllElementHtml(elementData);
				}
			});
		}
		start(){
			const selectorElementList = this.pickupSearchElements();
			selectorElementList.forEach((elementData)=>{
				if(!!elementData){
					$("body").on("click",elementData.element,function(){
						$(this).append(browsedHtml);
					});
				}
			});
			setInterval(()=>{
				this.searchPage(selectorElementList);
			}, 1000);
		};
	}
	
	/**
	 * 其他操作,比如清空购物记录
	 */
	class OtherOperatObject{
		clearnRecordBrowsing(){
			if(confirm('此弹窗来自脚本-[🔥]!!网购小助手,不花冤枉钱\n是否要清空本地商品浏览记录?清空后将不可恢复...')){
				const commonTools = new CommonTools();
				commonTools.GMsetValue(recordBrowsingHistoryKey,[]);
			}
		}
		start(){
			GM_registerMenuCommand("清空商品浏览记录",()=>{
				this.clearnRecordBrowsing();
			});
			const listener = new window.keypress.Listener();
			listener.simple_combo("shift c", ()=>{
				this.clearnRecordBrowsing();
			});
		}
	}
	
	(new Coupon()).start();
	(new SearchPageObject()).start();
	(new OtherOperatObject()).start();
})();