在您安装前,Greasy Fork 希望您知道此脚本包含可能不受欢迎的功能,也许会帮助脚本作者获利,而不能给你带来任何收益。
作者从这份脚本获得佣金,例如透过改写链接或提供优惠券代码以包含推荐或附属代码。
脚本作者的说明:
【此提示为GreasyFork代码规范要求含有查券功能的脚本必须添加,实际使用无任何强制跳转,代码可查,请知悉】
用电脑端访问淘宝、天猫、京东等不会主动领取优惠券,此脚本可以把只有APP端能看到的或本来就隐藏的大额优惠券给查询出来,有券不领非好汉~ 脚本采用低侵入形式,不会破坏网页结构,大家可以放心使用
目前为
// ==UserScript== // @name 网购省钱小助手:自动查询京东、淘宝、聚划算、天猫等隐藏的优惠券;自动历史价格查询;界面优化等;低侵入、持续维护更新😈 // @name:zh 网购省钱小助手:自动查询京东、淘宝、聚划算、天猫等隐藏的优惠券;自动历史价格查询;界面优化等;低侵入、持续维护更新😈 // @name:zh-TW 網購省錢小助手:自動查詢京東、淘寶、聚划算、天貓等隱藏的優惠券;自動曆史價格查詢;界面優化等;低侵入、持續維護更新😈 // @namespace coupon_namespace_20230625 // @version 2.0.1 // @description 用电脑端访问淘宝、天猫、京东等不会主动领取优惠券,此脚本可以把只有APP端能看到的或本来就隐藏的大额优惠券给查询出来,有券不领非好汉~ 脚本采用低侵入形式,不会破坏网页结构,大家可以放心使用 // @description:zh 用电脑端访问淘宝、天猫、京东等不会主动领取优惠券,此脚本可以把只有APP端能看到的或本来就隐藏的大额优惠券给查询出来,有券不领非好汉~ 脚本采用低侵入形式,不会破坏网页结构,大家可以放心使用 // @description:zh-TW 用電腦端訪問淘寶、天貓、京東等不會主動領取優惠券,此指令碼或直譯式程式可以把只有APP端能看到的或本來就隱藏的大額優惠券給查詢出來,有券不領非好漢~ 指令碼或直譯式程式採用低侵入形式,不會破壞網頁結構,大家可以放心使用 // @author huahuacat // @icon data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAAAXNSR0IArs4c6QAABFFJREFUWEfFl11oHFUUx/9nZne7s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/DaNB/nGvPrwyRmqyv3XyotGmJdbxuNK0o6fIeHNS/ZgYAqyw4H3sJYs0mkGT9dbMD4ZNjiH8eQvLied2EfPKkfGi41JBlswM16H8T4If19RQDuzIKqLF8Dm1v4xAhFHtf9LQPnVkUQFNGOpUDJGC/bhiL34JIJAuGEH2yIh0a7s9qSDuPalDZBuDTtJ7PqOAaxFJFILDSkkZf60Cv1dYcz/I5iKMAKrXNfOo6+OhE3ghU5LmGspIGueX0kN2mnD8m/HjjXWosvosEvKaB8PFJ8AnTzWb2LkvXSXJ/IrcNNOWizQmgl6B798poKvYMgT/N/hit5/GED4mkA0ScHGKci0IUTud3olv8TGq1eTJZ0OQNkOskhepvO8B/AOOGMHhVlZkAAAAASUVORK5CYII= // @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/* // @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 // @connect tt.shuqiandiqiu.com // @connect j.jiayoushichang.com // @grant GM_openInTab // @grant GM.openInTab // @grant GM_getValue // @grant GM.getValue // @grant GM_setValue // @grant GM.setValue // @grant GM_xmlhttpRequest // @grant GM.xmlHttpRequest // @license AGPL License // @antifeature referral-link 【此提示为GreasyFork代码规范要求含有查券功能的脚本必须添加,实际使用无任何强制跳转,代码可查,请知悉】 // @charset UTF-8 // @run-at document-idle // ==/UserScript== (function () { 'use strict'; /** * 公共的方法 */ 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){ 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"; } 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=200){ return new Promise((resolve,reject) =>{ let totalDelay = 0; let elementInterval = setInterval(()=>{ if(totalDelay >= 3000){ //总共检查3s,如果还是没找到,则返回 reject(false); clearInterval(elementInterval); } let element = document.querySelector(selector); let result = allowEmpty ? !!element : (!!element && !!element.innerHTML); if(result){ clearInterval(elementInterval); resolve(element); }else{ totalDelay += delay; } }, delay); }); } } /** * 优惠券相关功能 */ class Coupon{ platforms = ["detail.tmall.com", "item.taobao.com", "item.jd.com", "item.yiyaojd.com", "npcitem.jd.hk", "detail.tmall.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{ const titleObj = await this.commonTools.getElementAsync("[class='tb-main-title']", false); goodsName = titleObj.getAttribute("data-title"); if(!goodsName){ 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); 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); goodsName = titleObj.textContent; }catch(e){} } 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); } } async createCouponHtml(platform, goodsId, goodsName){ if(!platform || !goodsId){ return "kong"; } const goodsCouponUrl = "http://tt.shuqiandiqiu.com/api/coupon/discover?no=5&v=1.0.2&pl="+platform+"&id="+goodsId+"&qu="+goodsName; const goodsPrivateUrl = "http://tt.shuqiandiqiu.com/api/private/change/coupon?no=5&v=1.0.2&platform="+platform+"&id="; try{ const data = await this.commonTools.request("GET", goodsCouponUrl, null); if(data.code=="success" && !!data.result){ const result = JSON.parse(data.result).data; if(!result || result==="null" || !result.hasOwnProperty("css") || !result.hasOwnProperty("html") || !result.hasOwnProperty("handler")){ return "kong"; } const cssText = result.css, htmlText = result.html, handler = result.handler, templateId = result.templateId; if(!cssText || !htmlText || !handler){ return "kong"; } $("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); } } const $template = $("#"+templateId); if($template.length == 0){ return "kong"; } const couponElementA = $template.find("a[name='cpShUrl']"); const couponId = $template.data("id"); 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 "kong"; } 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); } return img; } } setInterval(()=>{ $template.find("*").each(function(){ $(this).removeAttr("data-spm-anchor-id"); }); },400); } }catch(e){ console.log("createCouponHtml:",e); } return "kong"; } showGoodsQRcode(platform, qrcodeImage){ if(platform==="jd"){ //京东不需要这个方法 return; } const elementId = Math.ceil(Math.random()*100000000)+"qrcode"; const width = 130; const title = platform=="jd" ? "京东APP扫码查看此商品":"淘宝APP扫码查看此商品"; const text = platform=="jd" ? window.location.href : window.location.href.split("?")[0] + "?id="+this.commonTools.getParamterQueryUrl(window.location.search, "id"); var html = ` <div style="position:fixed;right:50px;bottom:20px;z-index:99999999;padding:5px;background-color:#f6f6f6;border-radius:3px;-webkit-box-shadow:0px 10px 39px 10px rgba(52,53,53,0.22);-moz-box-shadow: 0px 10px 39px 10px rgba(52,53,53,0.22);box-shadow: 0px 10px 39px 10px rgba(52,53,53,0.22);"> <div style='font-size:11px;color:#ff5000;font-weight:bold;margin-bottom:4px;'>`+title+`</div> <div style='width:`+width+`px;height:`+width+`px;margin:0px auto;' id='`+elementId+`'></div> </div> `; $("body").append(html); if("kong"==qrcodeImage){ jQuery('#'+elementId).qrcode({ render: "canvas", width: width, height: width, foreground: "#000", background: "#FFF", text: text }); }else{ var canvas = document.createElement("canvas"); canvas.width = width; canvas.height = width; document.getElementById(elementId).appendChild(canvas); var cxt = canvas.getContext("2d"); var imgData = new Image(); imgData.src = qrcodeImage; imgData.onload=function(){ cxt.drawImage(imgData, 0, 0, width, width); } } } async start(){ if(this.isRun()){ this.runAliDeceptionSpm(); const platform = this.commonTools.getPlatform(); if(!!platform){ const goodsData = await this.getGoodsData(platform); const qrcodeImage = await this.createCouponHtml(platform, goodsData.goodsId, goodsData.goodsName); this.showGoodsQRcode(platform, qrcodeImage); } if(platform=="tmall"){ //tmall如果sku太多就折叠 const skuItemWrapper = await this.commonTools.getElementAsync("[class='skuItemWrapper']", false); if(skuItemWrapper != null){ const { style } = skuItemWrapper; style.maxHeight = "350px"; style.overflow = "auto"; } } } } } class SearchPageObject{ intervalIsRunComplete = true; //定时任务一个循环是否完成 constructor(){ this.commonTools = new 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) { //天猫超市 selectorElementList.push({"element":".product", "page":"tmall_chaoshi_search"}); selectorElementList.push({"element":".chaoshi-recommend-list .chaoshi-recommend-item", "page":"tmall_chaoshi_search_new"}); //新天猫超市 }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; } createAllElementHtml(elementData){ //为所有的商品创建提示 const self = this; $(elementData.element).each(function(){ //遍历所有的商品框 self.createOneElementHtml($(this), elementData); }); self.intervalIsRunComplete = true; } /** * 为商品box添加有券提醒 * @param {Object} $element 每一个商品box * @param {Object} elementData id and page */ async createOneElementHtml($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_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==="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; } // console.log(goodsDetailUrl); var analysisData = null; if(page==="jd" || page==="jd_hk"){ var jdId = this.commonTools.getEndHtmlIdByUrl(goodsDetailUrl); if(!!jdId) analysisData = {"id":jdId, "platform":"jd"}; }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; } try{ const searchUrl = "http://j.jiayoushichang.com/api/ebusiness/coupon/exist/"+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){} $element.attr("completebox","true"); } searchPage(selectorElementList){ if(!this.intervalIsRunComplete){ return; } selectorElementList.forEach((elementData)=>{ if(!!elementData){ this.createAllElementHtml(elementData); } }); } start(){ const selectorElementList = this.pickupSearchElements(); setInterval(()=>{ this.searchPage(selectorElementList); }, 500); }; } (new Coupon()).start(); (new SearchPageObject()).start(); })();