// ==UserScript== // @name 省神优惠券,简单易用的淘宝天猫阿里大药房商品优惠券,并且提供同类商品大额优惠券推荐! // @namespace https://tsr.itwashot.com/ // @version 0.1.3 // @description 简单易用的淘宝天猫阿里大药房优惠券。并提供同类商品大额优惠券推荐。脚本将持续更新,后面陆续支持拼多多,京东等平台。 // @author Kevin Lelf // @match *://*.taobao.com/* // @match *://*.tmall.com/* // @match *://*.liangxinyao.com/* // @match *://chaoshi.detail.tmall.com/* // @match *://*.tmall.hk/* // @connect tsr.itwashot.com // @require https://cdn.bootcss.com/jquery/3.4.1/jquery.min.js // @require https://cdn.bootcss.com/materialize/1.0.0-rc.2/js/materialize.min.js // @resource lelf-materialcss https://cdn.jsdelivr.net/gh/lelf2005/cdn@master/material.css?v=20200630 // @run-at document-end // @grant GM_addStyle // @grant GM_getResourceText // @downloadURL none // ==/UserScript== (function() { 'use strict'; var $ = $ || window.$; var materialcss = GM_getResourceText('lelf-materialcss'); GM_addStyle(materialcss); var apiTBQueryById = 'https://honey-jewelry.com/taobao/getCoupon/'; //var apiTBQueryById = 'http://localhost:8080/getCoupon/'; var tbDetailUrls = ["//item.taobao.com/item.htm","//detail.tmall.com/item.htm", "//chaoshi.detail.tmall.com/item.htm", "//detail.tmall.hk/hk/item.htm","//detail.tmall.hk/item.htm" ]; initCss(); var productId; if (isTBDetailPage(location.href)) { productId = window.location.href.split("id=")[1].split('&')[0]; $.get(apiTBQueryById + productId, function(data) { var htmlCoupon = ''; var htmlSimilarItems = ''; if(data.otherRecommends.length > 0){ for(let i in data.otherRecommends) { htmlSimilarItems += '

'+data.otherRecommends[i].coupon_info+'

'; } } if (data.coupon_amount) { htmlCoupon = '
' + data.coupon_amount + '优惠券

' + data.coupon_info + '

领取

剩余:' + data.coupon_remain_count + '

类似商品'+htmlSimilarItems+'

更多大额券...

'; } else { htmlCoupon = '
暂无

' + data.coupon_info + '

同类券

剩余:' + data.coupon_remain_count + '

类似商品'+htmlSimilarItems+'

更多大额券...

'; } //if (data.coupon_amount) { if (location.href.indexOf('//detail.tmall.') != -1) { $('.tm-fcs-panel') .after(htmlCoupon); } else if (location.href.indexOf('//chaoshi.detail.tmall.') != -1) { $('.tm-fcs-panel') .after(htmlCoupon); } else { $('ul.tb-meta') .after(htmlCoupon); } //} $("[id=lelf_rank]").click(function(){ getTopItems(); $('#lelf_modal_rank').modal(); }); }) } else { var selectorGroup = []; var locationUrl = location.href; if ( (locationUrl.indexOf("//list.tmall.com/coudan/search_product.htm") != -1) || (locationUrl.indexOf("//list.tmall.com/search_product.htm") != -1) || (locationUrl.indexOf("//list.tmall.com//search_product.htm") != -1) ) { selectorGroup.push(".product"); selectorGroup.push(".chaoshi-recommend-list .chaoshi-recommend-item"); } else if ( (locationUrl.indexOf("//s.taobao.com/search") != -1) || (locationUrl.indexOf("//s.taobao.com/list") != -1) ) { selectorGroup.push(".items .item"); } else if (locationUrl.indexOf("//list.tmall.hk/search_product.htm") != -1) { selectorGroup.push("#J_ItemList .product"); } else if (document.getElementById('J_ShopSearchResult')) { selectorGroup.push("#J_ShopSearchResult .item"); } if (selectorGroup && selectorGroup.length > 0) { initSelectorGroup(selectorGroup); initSearchEvent(); doQuery(); } } function getTopItems(){ var isAdded = $("#lelf_modal_rank"); if(isAdded.length > 0){ return; } var s = ' '; $("body").append(s); toggleLoader(true); // $.get('http://localhost:8080/prodQuery/1/1/'+productId+'/20/1', function(data) { $.get('https://honey-jewelry.com/taobao/prodQuery/1/1/'+productId+'/50/1', function(data) { var colors = ["lelf-gold","lelf-silver","lelf-orange","lelf-blue"]; var item_color = 0; $("#itemcat").html("类似商品推荐"); var topItems =data; var htmlItems = ''; for(var i=0;i 0){ strCoupon = ''+topItems[i].coupon.coupon_amount+'元券'; } var str_url = topItems[i].clickUrl; if(topItems[i].coupon.coupon_share_url){ str_url = topItems[i].coupon.coupon_share_url; } htmlItems = htmlItems + '
'+ '
'+ '
'+ '
'+(i+1)+'
'+ '
'+ '
'+ '
'+ '
'+ '
'+ ' '+ '
'+ '
'+ '
'+ '

'+topItems[i].title+'

'+ '
价格 ¥'+topItems[i].current_price+''+strCoupon+'
'+ '
'+ '
'+ '
30天销售'+topItems[i].volume+'
'+ ' 领券购买'+ '
'+ '
'+ '
'+ '
'+ '
' } $("#lelf-top-items").html(htmlItems); }) } function toggleLoader(flag){ if(flag){ var strHtml='
'; $("#lelf-top-items").append(strHtml); }else{ $("#loader").remove(); } } function initSelectorGroup(selectorGroup) { setInterval(function() { selectorGroup.forEach(function(selector) { $(selector) .each(function() { initQueryItem(this); }); }); }, 2500); }; function initSearchEvent() { $(document) .on("click", ".boxArea", function() { var $this = $(this); if ($this.hasClass("boxQuerying")) { $this.removeClass("boxQuerying"); } else if ($this.hasClass("boxWaiting")) { doQueryItem(this); } else { $this.addClass("boxQuerying"); } }); }; function doQuery() { setInterval(function() { $(".boxWaiting") .each(function() { doQueryItem(this); }); }, 2800); }; function initQueryItem(selector) { var $this = $(selector); if ($this.hasClass("boxDone")) { return; } $this.addClass("boxDone") var nid = $this.attr("data-id"); if (!isVailidItemId(nid)) { nid = $this.attr("data-itemid"); } if (!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 (!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 (isValidNid(nid)) { appendQueryHtml($this, nid); } }; function appendQueryHtml(selector, nid) { selector.append('
待查询
'); }; function doQueryItem(selector) { var $this = $(selector); $this.removeClass("boxWaiting"); var nid = $this.attr("data-nid"); $.get(apiTBQueryById + nid, function(data) { if (data.coupon_amount && data.coupon_amount > 0) { showQueryFound($this, data.coupon_amount); } else { showQueryNotFound($this); } }) }; function showQueryFound(selector, couponMoney) { selector.html('有券(减' + couponMoney + '元)'); }; function showQueryNotFound(selector) { selector.addClass("boxQuerying"); selector.html('暂无优惠'); }; function isTBDetailPage(url) { for (var i = 0; i < tbDetailUrls.length; i++) { if (url.indexOf(tbDetailUrls[i]) > 0) { return true; } } return false; }; function isVailidItemId(itemId) { if (!itemId) { return false; } var itemIdInt = parseInt(itemId); if (itemIdInt == itemId && itemId > 10000) { return true; } else { return false; } }; function isValidNid(nid) { if (!nid) { return false; } else if (nid.indexOf('http') >= 0) { if (isTBDetailPage(nid) || nid.indexOf("//detail.ju.taobao.com/home.htm") > 0) { return true; } else { return false; } } else { return true; } }; function addCss(cssText) { var acss = document.createElement('style'); acss.textContent = cssText; var doc = (document.head || document.documentElement); doc.appendChild(acss); } function initCss() { addCss(`.stamp * { padding: 0; margin: 0; list-style: none; } .stamp { width: 342px; padding: 0 10px; margin-top: 5px; position: relative; overflow: hidden; display: inline-block; } .stamp:before { content: ''; position: absolute; top: 0; bottom: 0; left: 10px; right: 10px; z-index: -1; } .stamp:after { content: ''; position: absolute; left: 10px; top: 10px; right: 10px; bottom: 10px; z-index: -2; } .stamp i { position: absolute; right: 20%; bottom: 45px; height: 190px; width: 390px; background-color: rgba(255,255,255,.15); transform: rotate(-30deg); } .stamp .par { float: left; padding: 16px 15px; width: 180px; border-right: 2px dashed rgba(255,255,255,.3); text-align: center; } .stamp .par p { color: #fff; font-size: 16px; line-height: 21px; } .stamp .par span { font-size: 50px; color: #fff; margin-right: 5px; line-height: 65px; } .stamp .par .sign { font-size: 34px; } .stamp .par sub { position: relative; top: -5px; color: rgba(255,255,255,.8); } .stamp .copy { display: inline-block; padding: 21px 14px; width: 100px; font-size: 30px; color: rgb(255,255,255); text-align: center; } .stamp .copy p { font-size: 14px; margin-top: 15px; } .stamp .copy a { color : white; } .similar { display: inline-block; vertical-align: top; font-size: 14px; background: #F39B00; margin-left: 5px; margin-top: 5px; padding: 9px 25px; color: white; } .similar a { color : white; } .stamp01 { background: #F39B00; background: radial-gradient(rgba(0, 0, 0, 0) 0, rgba(0, 0, 0, 0) 5px, #F39B00 5px); background-size: 15px 15px; background-position: 9px 3px; } .stamp01:before { background-color: #F39B00; } #tb-cool-area { border: 1px solid #eee; margin: 0 auto; position: relative; clear: both; display: none; } #tb-cool-area .tb-cool-area-home { position: absolute; top: 5px; right: 10px; z-index: 10000; } #tb-cool-area .tb-cool-area-home a { cursor: pointer; color: #515858; font-size: 10px; text-decoration: none; } #tb-cool-area .tb-cool-area-home a.new-version { color: #ff0036; } #tb-cool-area .tb-cool-area-benefit { width: 240px; float: left; } #tb-cool-area .tb-cool-area-benefit .tb-cool-quan-qrcode { text-align: center; min-height: 150px; margin-top: 40px; } #tb-cool-area .tb-cool-area-benefit .tb-cool-quan-qrcode canvas,#tb-cool-area .tb-cool-area-benefit .tb-cool-quan-qrcode img { margin: 0 auto; } #tb-cool-area .tb-cool-area-benefit .tb-cool-quan-title { margin-top: 20px; color: #000; font-size: 14px; font-weight: 700; text-align: center; } #tb-cool-area .tb-cool-area-benefit .tb-cool-quan-title span { color: #ff0036; font-weight: 700; } #tb-cool-area .tb-cool-area-benefit .tb-cool-quan-action { margin-top: 10px; text-align: center; } #tb-cool-area .tb-cool-area-benefit .tb-cool-quan-action a { text-decoration: none; } #tb-cool-area .tb-cool-area-benefit .tb-cool-quan-action .tb-cool-quan-button { min-width: 120px; padding: 0 8px; line-height: 35px; color: #fff; background: #ff0036; font-size: 13px; font-weight: 700; letter-spacing: 1.5px; margin: 0 auto; text-align: center; border-radius: 15px; display: inline-block; cursor: pointer; } #tb-cool-area .tb-cool-area-benefit .tb-cool-quan-action .tb-cool-quan-button.quan-none { color: #000; background: #bec5c5; } #tb-cool-area .tb-cool-area-history { height: 300px; overflow: hidden; position: relative; } #tb-cool-area .tb-cool-area-history #tb-cool-area-chart,#tb-cool-area .tb-cool-area-history .tb-cool-area-container { width: 100%; height: 100%; } #tb-cool-area .tb-cool-area-history .tb-cool-history-tip { position: absolute; margin: 0; top: 50%; left: 50%; letter-spacing: 1px; font-size: 15px; transform: translateX(-50%) translateY(-50%); } #tb-cool-area .tb-cool-area-table { margin-top: 10px; position: relative; overflow: hidden; } #tb-cool-area .tb-cool-quan-tip { position: absolute; margin: 0; top: 50%; left: 50%; letter-spacing: 1px; font-size: 15px; opacity: 0; transform: translateX(-50%) translateY(-50%); } #tb-cool-area .tb-cool-quan-tip a { color: #333; font-weight: 400; text-decoration: none; } #tb-cool-area .tb-cool-quan-tip a:hover { color: #ff0036; } #tb-cool-area .tb-cool-area-table .tb-cool-quan-table { width: 100%; font-size: 14px; text-align: center; } #tb-cool-area .tb-cool-area-table .tb-cool-quan-table tr td { padding: 4px; color: #1c2323; border-top: 1px solid #eee; border-left: 1px solid #eee; } #tb-cool-area .tb-cool-area-table .tb-cool-quan-table tr td span { color: #ff0036; font-weight: 700; } #tb-cool-area .tb-cool-area-table .tb-cool-quan-table tr td:first-child { border-left: none; } #tb-cool-area .tb-cool-area-table .tb-cool-quan-table .tb-cool-quan-link { width: 60px; line-height: 24px; font-size: 12px; background: #ff0036; text-decoration: none; display: inline-block; } #tb-cool-area .tb-cool-area-table .tb-cool-quan-table .tb-cool-quan-link-enable { cursor: pointer; color: #fff; } #tb-cool-area .tb-cool-area-table .tb-cool-quan-table .tb-cool-quan-link-disable { cursor: default; color: #000; background: #ccc; } #tb-cool-area .tb-cool-quan-empty .tb-cool-quan-tip { opacity: 1; } #tb-cool-area .tb-cool-quan-empty .tb-cool-quan-table { filter: blur(3px); -webkit-filter: blur(3px); -moz-filter: blur(3px); -ms-filter: blur(3px); } .boxArea { position: absolute; top: 10px; left: 5px; z-index: 9999; } .boxWaiting { cursor: pointer; } .boxDone { position: relative; } .boxInfo { width: auto!important; height: auto!important; padding: 6px 8px!important; font-size: 13px; color: #fff!important; border-radius: 16px; cursor: pointer; } .boxInfo,.boxInfo:hover,.boxInfo:visited { text-decoration: none!important; } .boxInfo-default { background: #3186fd!important; } .boxInfo-find { background: #f54848!important; } .boxInfo-empty { color: #000!important; background: #ccc!important; } .boxQuerying { opacity: .45; } .mui-zebra-module .boxInfo { font-size: 10px; } .import-shangou-itemcell .boxArea,.zebra-ziying-qianggou .boxArea { right: 10px; left: auto; } .item_s_cpb .boxArea { top: auto; bottom: 10px; } .j-mdv-chaoshi .m-floor .boxArea a { width: auto; height: auto; } .left-wider .proinfo-main { margin-bottom: 40px; } .detailHd .m-info { margin-bottom: 20px; } .tb-cool-quan-date { color: #233b3d; font-weight: 400; font-size: 12px; } .tb-cool-area-has-date .tb-cool-quan-qrcode { margin-top: 30px!important; } .tb-cool-area-has-date .tb-cool-quan-title { margin-top: 10px!important; }`); } })();