// ==UserScript== // @name 【省一省 领优惠券 高额返现 历史价格】--淘宝、天猫、京东内部优惠券,可显示返现金额,历史价格走势,配合APP扫码下单后即可获得返现~~长期更新,放心使用。 // @namespace cyzlizhe // @version 1.3 // @description 在淘宝、天猫、京东的【商品列表页】和【商品详情页】上显示优惠券详细信息及返现金额,无需进入商品详情页即可查看,商品详情页可直接领券,功能简单,显示直观,支持在商品详情页通过「花前省一省」APP扫码,直接在APP进入商品、领券及获得返现。在代码的编写过程中,参考了作者@simples的代码,受益匪浅。 // @author cyzlizhe // @icon https://s1.ax1x.com/2020/09/15/wybNRS.png // @match *://*.taobao.com/* // @match *://*.tmall.com/* // @match *://*.tmall.hk/* // @match *://*.liangxinyao.com/* // @match *://*.jd.com/* // @match *://*.jd.hk/* // @exclude *://login.taobao.com/* // @exclude *://pages.tmall.com/* // @exclude *://uland.taobao.com/* // @require https://cdn.bootcdn.net/ajax/libs/jquery/1.6.3/jquery.js // @require https://cdn.bootcss.com/jquery.qrcode/1.0/jquery.qrcode.min.js // @require https://cdn.bootcdn.net/ajax/libs/apexcharts/3.9.0/apexcharts.min.js // @run-at document-start // @grant GM_xmlhttpRequest // @connect gwdang.com // @note 2020年9月25日09:23:38 修复京东商品搜索页返现金额显示不正确的bug,修复京东商品返现二维码扫码后找不到商品的bug。 // @note 2020年9月23日09:54:58 京东支持历史价格查询了,优化界面,自动隐藏需要验证和没有历史数据的商品趋势图 // @note 2020年9月22日08:51:05 修复淘宝主页异常显示,修复在无历史价格时仍旧提示验证,修复验证窗口在某种情况下无法关闭,开始适配京东历史价格 // @note 2020年9月21日08:43:03 修复历史价格不显示的bug,调用购物党接口,增加验证环节,验证后可自动刷新显示。 // @note 2020年9月18日18:03:50 新增历史价格显示(目前只支持淘宝),点击可以隐藏/显示,修复京东详情页,价格出来的慢时候代码报错 // @note 2020年9月17日12:49:27 修复部分页面下优惠券会出现两个的问题。 // @note 2020年9月16日15:05:21 修复京东列表页懒加载后隐藏标签无效的bug,修复部分阿里健康大药房不显示优惠券的bug // @note 2020年9月15日16:05:04 新增对京东新款,京东优评页面的支持,部分界面调整 // @note 2020年9月14日17:32:30 更新,修复部分页面不显示的bug,修复返现金额显示不准确。 // @note 2020年9月13日22:57:15 更新,新增京东优惠券及返现的支持,修复上一版中天猫超市优惠券查询无反应的bug。 // @note 2020年9月10日11:37:20 更新,修复返现金额查询时间长的bug,京东的查券返现功能正在适配中。 // @downloadURL none // ==/UserScript== (function () { "use strict"; var $2 = $.noConflict(); // 第二个加载的jQuery对象变成了 $2 // Your code here... var style = document.createElement("link"); style.href = "https://www.youyizhineng.top/query_coupon/query_coupon.css"; style.rel = "stylesheet"; style.type = "text/css"; document.getElementsByTagName("head").item(0).appendChild(style); style = document.createElement("link"); style.href = "https://www.youyizhineng.top/query_coupon/coupon_style.css"; style.rel = "stylesheet"; style.type = "text/css"; document.getElementsByTagName("head").item(0).appendChild(style); var obj = {}; var couponArea; var jd_item_list = ''; var jd_data_list_back = ''; var check_url = ''; var options = { title: { // 显示折现图的title text: '花前省一省-商品历史价格走势图', fontSize: '12px' }, markers: { size: 0, colors: ['#fbb5b0'], }, chart: { height: 200, width: "100%", type: "area", animations: { initialAnimation: { enabled: false } } }, series: [ { name: "价格", data: [] } ], xaxis: { type: "datetime", labels: { datetimeFormatter: { year: 'yyyy', month: 'MM \-yy', day: 'yyyy-MM-dd', hour: 'HH:mm' } } }, stroke: { curve: 'smooth', width: [0.5, 0.5, 0.5] }, colors: ['#F44336'], dataLabels: { enabled: false, style: { colors: ['#000000'] } }, tooltip: { x: { format: 'yyyy-MM-dd' }, y: [{ formatter: function (y) { if (typeof y !== "undefined") { return y.toFixed(0) + "元"; } return y; } }] } } var chart; //列表页面操作 obj.initSearchHtml = function (selectorList) { setInterval(function () { selectorList.forEach(function (selector) { obj.initSearchItemSelector(selector); }); }, 1000); }; obj.initSearchItemSelector = function (selector) { $2(selector).each(function () { obj.initSearchItem(this); }); }; obj.initSearchItem = function (selector) { var $this = $2(selector); var nid; if ($this.hasClass("tb-cool-box-already")) { return; } else { $this.addClass("tb-cool-box-already"); } if (obj.site_type() == "taobao_lst_page") { nid = $this.attr("data-id"); if (!obj.isVailidItemId(nid)) { nid = $this.attr("data-itemid"); } if (!obj.isVailidItemId(nid)) { if ($this.attr("href")) { nid = location.protocol + $this.attr("href"); } else { var $a = $this.find("a"); if (!$a.length) { return; } nid = $a.attr("data-nid"); if (!obj.isVailidItemId(nid)) { if ($a.hasClass("j_ReceiveCoupon") && $a.length > 1) { nid = location.protocol + $2($a[1]).attr("href"); } else { nid = location.protocol + $a.attr("href"); } } } } } else if (obj.site_type() == "jingdong_lst_page") { nid = $this.attr("data-sku"); if (typeof (nid) == "undefined") { nid = $this.find('.price').attr("data-skuid"); } if (!obj.isVailidItemId(nid)) { nid = $this.find(".p-operate").find("a").attr("skuid"); } } if (obj.isValidNid(nid)) { obj.appenBasicQueryHtml($this, nid); } }; //图片上显示提示图标 obj.initSearchEvent = function () { $2(".tb-cool-box-area").live("click", function () { var Show_hide_div_id = $2(this).attr("name"); var a = document.getElementsByName(Show_hide_div_id)[0].style.opacity; for (let index = 0; index < document.getElementsByName(Show_hide_div_id).length; index++) { if (a == "" || a == "1") { document.getElementsByName(Show_hide_div_id)[index].style.opacity = "0.2"; } else { document.getElementsByName(Show_hide_div_id)[index].style.opacity = "1"; } } }); $2(".tb-cool-box-area-rm").live("click", function () { var Show_hide_div_id = $2(this).attr("name"); var a = document.getElementsByName(Show_hide_div_id)[0].style.opacity; for (let index = 0; index < document.getElementsByName(Show_hide_div_id).length; index++) { if (a == "" || a == "1") { document.getElementsByName(Show_hide_div_id)[index].style.opacity = "0.2"; } else { document.getElementsByName(Show_hide_div_id)[index].style.opacity = "1"; } } }); }; obj.basicQuery = function () { setInterval(function () { $2(".tb-cool-box-wait").each(function () { obj.basicQueryItem(this); }); }, 1000); }; obj.basicQuery_jd_list = function () { setInterval(function () { if ($2(".tb-cool-box-wait").length > 0) { jd_item_list = jd_item_list.substr(0, jd_item_list.length - 1); obj.update_jd_list_data(jd_item_list); // console.log(jd_item_list); jd_item_list = ''; } if ($2(".tb-cool-box-wait-rm").length > 0 && jd_data_list_back != '') { // console.log($2(".tb-cool-box-wait-rm").length); // console.log(jd_data_list_back); $2(".tb-cool-box-wait-rm").each(function () { obj.basicQueryItem_jd(this, jd_data_list_back, 'refresh_cashback'); }); jd_data_list_back = ''; } }, 1500); }; obj.update_jd_list_data = function (jd_item_list) { url = "https://www.youyizhineng.top/query_coupon/query_coupon.php?operate=quert_list_jd&itemid_list=" + jd_item_list; $2.getJSON(url, function (data) { $2(".tb-cool-box-wait").each(function () { obj.basicQueryItem_jd(this, data, ''); }); jd_data_list_back = data; }); } obj.appenBasicQueryHtml = function (selector, nid) { if (obj.site_type() == "jingdong_lst_page") { jd_item_list = jd_item_list + nid + ","; } selector.append( '
' ); selector.append( '' ); }; obj.basicQueryItem = function (selector) { var $this = $2(selector); var url; $this.removeClass("tb-cool-box-wait"); var nid = $this.attr("data-nid"); url = "https://www.youyizhineng.top/query_coupon/query_coupon.php?operate=quert_single&itemid=" + nid; var xhr1 = new XMLHttpRequest();//第一步:新建对象 xhr1.open('GET', url, true);//第二步:打开连接 将请求参数写在url中 xhr1.send();//第三步:发送请求 将请求参数写在URL中 /** * 获取数据后的处理程序 */ xhr1.onreadystatechange = function () { if (xhr1.readyState == 4 && xhr1.status == 200) { var res = xhr1.responseText;//获取到json字符串,解析 var data = JSON.parse(res); if (data.couponmoney != 0 || data.return_money_rate != 0) { obj.showBasicQueryFind($this, data.couponmoney, data.return_money_rate, data.url2); } else { obj.showBasicQueryEmpty($this); } } } }; obj.basicQueryItem_jd = function (selector, data, flag) { if (flag == 'refresh_cashback') { var $this = $2(selector).prev(); } else { var $this = $2(selector); } var url; var each_couponmoney; var each_return_money_rate; var each_url2; if ($this.hasClass("tb-cool-box-wait")) { $this.removeClass("tb-cool-box-wait"); } else { return; } // $this.next().removeClass("tb-cool-box-wait-rm"); var nid = $this.attr("data-nid"); if (typeof (data[nid]) == "undefined") { each_couponmoney = 0; each_return_money_rate = 0; each_url2 = ''; } else { each_couponmoney = data[nid].couponmoney; each_return_money_rate = data[nid].return_money_rate; each_url2 = data.url2; } if (each_couponmoney != 0 || each_return_money_rate != 0) { obj.showBasicQueryFind($this, each_couponmoney, each_return_money_rate, each_url2) } else { obj.showBasicQueryEmpty($this); } }; obj.showBasicQueryFind = function (selector, couponMoney, rm_Money, url2) { var price; if (selector.find(".tb-cool-box-info-find").length > 0) { return; } if (couponMoney == "0") { selector.html( '无券' ); } else selector.html( '有券(减' + couponMoney + "元)" ); var url = location.href; if (url.indexOf("//s.taobao.com/search") > 0 || url.indexOf("//s.taobao.com/list") > 0) { price = selector.prev().find("strong").html(); if (url2 != '') { selector.prev().find(".J_ClickStat").attr("href", url2); selector.prev().prev().find(".pic").find("a").attr("href", url2); } } else if (url.indexOf("//list.tmall.com/search_product.htm") > 0) { price = selector.prev().find("em").attr('title'); if (price > 0) { price = selector.prev().find("em").attr('title'); if (url2 != '') { selector.prev().find(".productTitle").find("a").attr("href", url2); selector.prev().find(".productImg").attr("href", url2); } } else { price = selector.prev().find(".item-price").find("strong").html(); } } else if (url.indexOf("//list.tmall.hk/search_product.htm") > 0) { price = selector.prev().find("em").attr('title'); if (url2 != '') { selector.prev().find(".productTitle").find("a").attr("href", url2); selector.prev().find(".productImg").attr("href", url2); } } else if (url.indexOf("//maiyao.liangxinyao.com/shop/view_shop.htm") > 0) { price = selector.prev().prev().find(".c-price").html(); if (price > 0) { price = selector.prev().prev().find(".c-price").html(); if (url2 != '') { selector.prev().prev().find("a").attr("href", url2); selector.prev().prev().prev().find("a").attr("href", url2); } } else { price = selector.prev().find(".c-price").html(); if (url2 != '') { selector.prev().find("a").attr("href", url2); selector.prev().prev().find("a").attr("href", url2); } } } else if (url.indexOf("//search.jd.com/Search") > 0 || url.indexOf("//list.jd.com/list.html") > 0) { price = selector.prev().find(".p-price").find("i").html(); if (price > 0) { price = selector.prev().find(".p-price").find("i").html(); } } else if (url.toLowerCase().indexOf("//search.jd.hk/search".toLowerCase()) > 0) { price = selector.prev().find(".price").find("span").html().split('>')[2]; } else if (url.toLowerCase().indexOf("//www.jd.com/xinkuan".toLowerCase()) > 0) { price = selector.prev().find(".price").find("strong").html().split('¥')[1]; if (price == "暂无报价") { return; } } var rm_Money_clc = Math.round(Math.floor((price - couponMoney) * rm_Money * 1000) / 10) / 100; if (rm_Money_clc != 0) { selector.next().html( '返现(约' + rm_Money_clc + "元)" ); } else { selector.next().html( '无返现' ); } }; obj.showBasicQueryEmpty = function (selector) { // selector.addClass("tb-cool-box-info-translucent"); selector.html( '暂无优惠' ); selector .next() .html( '暂无返现' ); }; obj.site_type = function () { url = location.href; 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.liangxinyao.com/item.htm") > 0 || url.indexOf("//detail.tmall.hk/item.htm") > 0 ) { return "taobao_details_page"; } else if ( url.indexOf("//maiyao.liangxinyao.com/shop/view_shop.htm") > 0 || url.indexOf("//list.tmall.com/search_product.htm") > 0 || url.indexOf("//s.taobao.com/search") > 0 || url.indexOf("//list.tmall.hk/search_product.htm") > 0 ) { return "taobao_lst_page"; } else if ( url.indexOf("//search.jd.com/Search") > 0 || url.indexOf("//search.jd.hk/search") > 0 || url.indexOf("//www.jd.com/xinkuan") > 0 || url.indexOf("//list.jd.com/list.html") > 0 || url.indexOf("//search.jd.hk/Search") > 0 ) { return "jingdong_lst_page"; } else if ( url.indexOf("//item.jd.hk") > 0 || url.indexOf("//item.jd.com") > 0 ) { return "jingdong_details_page"; } } 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 ) { return true; } else { return false; } }; obj.DetailPageTB_or_TM_or_JD = function () { var url = location.href; if (url.indexOf("//item.taobao.com/item.htm") > 0 || url.indexOf("//detail.liangxinyao.com/item.htm") > 0) { return 1; } else if (url.indexOf("//detail.tmall.com/item.htm") > 0) { return 2; } else if (url.indexOf("//item.jd.com") > 0) { return 3; } }; obj.isVailidItemId = function (itemId) { if (!itemId) { return false; } var itemIdInt = parseInt(itemId); if (itemIdInt == itemId && itemId > 10000) { return true; } else { return false; } }; obj.isValidNid = function (nid) { if (!nid) { return false; } else if (nid.indexOf("http") >= 0) { if ( obj.isDetailPageTaoBao(nid) || nid.indexOf("//detail.ju.taobao.com/home.htm") > 0 ) { return true; } else { return false; } } else { return true; } }; obj.getprice = function (selector) { if (!nid) { return false; } else if (nid.indexOf("http") >= 0) { if ( obj.isDetailPageTaoBao(nid) || nid.indexOf("//detail.ju.taobao.com/home.htm") > 0 ) { return true; } else { return false; } } else { return true; } }; obj.send_get_req = function (url) { var xhr = new XMLHttpRequest();//第一步:新建对象 xhr.open('GET', url, true);//第二步:打开连接 将请求参数写在url中 xhr.send();//第三步:发送请求 将请求参数写在URL中 /** * 获取数据后的处理程序 */ xhr.onreadystatechange = function () { if (xhr.readyState == 4 && xhr.status == 200) { var res = xhr.responseText;//获取到json字符串,解析 } }; }; obj.get_tb_price = function (price_str) { var price = ''; if (price_str != null) { if (price_str.indexOf("-") > 0) { price = price_str.split("-")[0]; } else { price = price_str; } } return price; }; obj.get_data_jd = function () { if (location.href.length > 50) { return; } var url = "https://www.youyizhineng.top/query_coupon/query_coupon1.php?operate=get_info&data_i=" + location.href; $2.ajax({ url: url, async: false, timeout: 1000, // dataType: "json", success: function (data) { // console.log(data); var data_tmp = JSON.parse(data); // console.log(data_tmp.data_i); if (data_tmp.data_i != null) { window.location.href = data_tmp.data_i + "&ready=1"; } } }) // var xhr = new XMLHttpRequest();//第一步:新建对象 // xhr.open('GET', url, true);//第二步:打开连接 将请求参数写在url中 // xhr.send();//第三步:发送请求 将请求参数写在URL中 // /** // * 获取数据后的处理程序 // */ // xhr.onreadystatechange = function () { // if (xhr.readyState == 4 && xhr.status == 200) { // var res = xhr.responseText;//获取到json字符串,解析 // var data_tmp = JSON.parse(res); // console.log(data_tmp); // if (data_tmp.data_i != null) { // window.location.href = data_tmp.data_i + "&ready=1"; // } // } // } }; obj.generate_trend_data = function (all_begin_time, all_line) { if (all_line.length > 0) { for (let index = 0; index < all_line.length; index++) { var data_tmp = {}; var newTime = new Date(all_begin_time); newTime = newTime.setDate(newTime.getDate() + index); newTime = new Date(newTime); var newTime_d = (newTime.getMonth() + 1).toString().padStart(2, '0') + "-" + newTime.getDate().toString().padStart(2, '0') + "-" + newTime.getFullYear() + " GMT"; data_tmp["x"] = newTime_d; data_tmp["y"] = all_line[index]; options.series[0].data.push(data_tmp); } } }; obj.query_trend_data = function () { //获得价格波动var url = location.href; var gwdUrl = "https://browser.gwdang.com/extension/price_towards?url=" + encodeURIComponent(location.href); // console.log(gwdUrl); // console.log('1'); GM_xmlhttpRequest({ url: gwdUrl, method: 'GET', timeout: 10000, headers: { 'Content-Type': 'application/json', 'Accept': 'application/json', 'Cache-Control': 'public' }, onload: function (res) { //loadingMask.parentNode.removeChild(mask); const json = JSON.parse(res.responseText); const data = json; // console.log(data); if (data.is_ban == null) { // console.log(typeof (data.store)); var all_line; var all_begin_time; if ($2("#float_div").css("display") == "block") { location.reload(); } if (typeof (data.store) != "undefined" && data.store[0].all_line != null) { all_begin_time = data.store[0].all_line_begin_time; all_line = data.store[0].all_line; obj.generate_trend_data(all_begin_time, all_line); } else { options.title.text = "花前省一省-本商品暂无历史数据"; } // console.log(check_url); } else { options.title.text = "本次需要验证:【点击上方按钮进行验证】"; check_url = data.action.to; // console.log(check_url); } } }); } obj.add_iframe = function () { // console.log(check_url); // console.log(options); if (options.title.text == "花前省一省-本商品暂无历史数据") { $2(".image-status").attr("title", "历史数据加载成功"); $2(".image-status").attr("src", "http://huaqianshengyisheng.img.weiyuntop.com/oss/uploads/backend/202009/0_f627919f2c80d11eff1b42baceecd3bb.png"); $2(".status-span").html("经查询,本商品暂无历史数据"); $2("#coupon-wrap-trend").css("display", "none"); } else if (options.series[0].data.length > 0) { $2(".image-status").attr("title", "历史数据加载成功"); $2(".image-status").attr("src", "http://huaqianshengyisheng.img.weiyuntop.com/oss/uploads/backend/202009/0_f627919f2c80d11eff1b42baceecd3bb.png"); } else { //在chart上提示显示文字 $2(".trend-div").append('21321321321'); $2(".image-status").attr("title", "需要验证"); $2(".image-status").attr("src", "http://huaqianshengyisheng.img.weiyuntop.com/oss/uploads/backend/202009/0_cabaf81a605adaab13cbec5f328cd664.gif"); $2(".image-status").css("cursor", "pointer"); $2("#coupon-wrap-trend").css("display", "none"); $2(".status-span").html("← 点击左侧按钮验证"); $2("body").append(''); document.getElementById("float_div").style.left = (window.screen.width - 800) / 2 + "px"; document.getElementById("float_div").style.top = (window.screen.height - 500) / 2 + "px"; $2("#float_div").append(''); $2("#iframe_check").attr("src", check_url); $2("#iframe_check").attr("scrolling", "no"); $2("#float_div").append('" + data.couponexplain + "
' +
data.couponstarttime +
"
" +
data.couponendtime +
'
" + data.couponexplain + "
' +
data.couponstarttime +
"
" +
data.couponendtime +
'