// ==UserScript== // @name 【简单查券-简单返现】--领取淘宝、天猫优惠券,并获得返现。 // @namespace cyzlizhe // @version 0.1 // @description 在淘宝、天猫的商品列表页和商品详情页上显示优惠券详细信息及返现金额,功能简单,显示直观,支持在商品详情页通过「花前省一省」APP扫码,直接在APP进入商品、领券及获得返现。在代码的编写过程中,参照了作者@simples的代码,受益匪浅。 // @author cyzlizhe // @homepage https://www.youyizhineng.top/ // @match *://*.taobao.com/* // @match *://*.tmall.com/* // @match *://*.tmall.hk/* // @match *://*.liangxinyao.com/* // @exclude *://login.taobao.com/* // @exclude *://pages.tmall.com/* // @exclude *://uland.taobao.com/* // @require https://cdn.staticfile.org/jquery/1.12.4/jquery.min.js // @require https://cdn.bootcss.com/jquery.qrcode/1.0/jquery.qrcode.min.js // @grant none // @downloadURL none // ==/UserScript== (function () { "use strict"; // 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 = {}; //列表页面操作 obj.initSearchHtml = function (selectorList) { setInterval(function () { selectorList.forEach(function (selector) { obj.initSearchItemSelector(selector); }); }, 3000); }; obj.initSearchItemSelector = function (selector) { $(selector).each(function () { obj.initSearchItem(this); }); }; obj.initSearchItem = function (selector) { var $this = $(selector); if ($this.hasClass("tb-cool-box-already")) { return; } else { $this.addClass("tb-cool-box-already"); } var 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 + $($a[1]).attr("href"); } else { nid = location.protocol + $a.attr("href"); } } } } if (obj.isValidNid(nid)) { obj.appenBasicQueryHtml($this, nid); } }; //图片上显示提示图标 obj.initSearchEvent = function () { $(document).on("click", ".tb-cool-box-area", function () { var Show_hide_div_id = $(this).attr("id"); var a = document.getElementById(Show_hide_div_id).style.opacity; if (a == "" || a == "1") { document.getElementById(Show_hide_div_id).style.opacity = "0.2"; } else { document.getElementById(Show_hide_div_id).style.opacity = "1"; } }); $(document).on("click", ".tb-cool-box-area-rm", function () { var Show_hide_div_id = $(this).attr("id"); var a = document.getElementById(Show_hide_div_id).style.opacity; if (a == "" || a == "1") { document.getElementById(Show_hide_div_id).style.opacity = "0.2"; } else { document.getElementById(Show_hide_div_id).style.opacity = "1"; } }); }; obj.basicQuery = function () { setInterval(function () { $(".tb-cool-box-wait").each(function () { obj.basicQueryItem(this); }); }, 3000); }; obj.appenBasicQueryHtml = function (selector, nid) { selector.append( '
' ); selector.append( '' ); }; obj.basicQueryItem = function (selector) { var $this = $(selector); $this.removeClass("tb-cool-box-wait"); var nid = $this.attr("data-nid"); var url = "https://www.youyizhineng.top/query_coupon/query_coupon.php?operate=quert_single&itemid=" + nid; $.getJSON(url, function (data) { // alert(data) if (data.couponmoney != 0 || data.return_money_rate != 0) { obj.showBasicQueryFind($this, data.couponmoney, data.return_money_rate); } else { obj.showBasicQueryEmpty($this); } }); // $.ajax({ // type: "get", // dataType: "json", // url: url, // success: function (data) { // // alert(data) // } // }); }; obj.showBasicQueryFind = function (selector, couponMoney, rm_Money) { var price; 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(); //淘宝、天猫超市展示页 } else if(url.indexOf("//list.tmall.com/search_product.htm") > 0) { price = selector.prev().find("em").attr('title'); //淘宝、天猫超市展示页 } else if(url.indexOf("//list.tmall.hk/search_product.htm") > 0) { price = selector.prev().find("em").attr('title'); //淘宝、天猫超市展示页 } 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(); } else { price = selector.prev().find(".c-price").html(); } } selector.next().html( '返现(约' + Math.round(Math.floor(price * rm_Money * 1000) / 10) / 100 + "元)" ); }; obj.showBasicQueryEmpty = function (selector) { // selector.addClass("tb-cool-box-info-translucent"); selector.html( '暂无优惠' ); selector .next() .html( '暂无返现' ); }; 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 = function () { var url = location.href; if (url.indexOf("//item.taobao.com/item.htm") > 0) { return 1; } else { return 2; } }; 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; } }; if (obj.isDetailPageTaoBao(location.href)) { var params = location.search.split("?")[1].split("&"); for (var index in params) { if (params[index].split("=")[0] == "id") { var productId = params[index].split("=")[1]; break; } } var url = "https://www.youyizhineng.top/query_coupon/query_coupon.php?operate=quert_single&itemid=" + productId; $.getJSON(url, function (data) { var couponArea; if (data.couponmoney == 0) { couponArea = '" + data.couponexplain + "
' +
data.couponstarttime +
"
" +
data.couponendtime +
'