作者: whooyun发表于: 2018-12-29 16:23
// ==UserScript== // @name 淘宝天猫优惠券佣金查询 // @namespace http://tampermonkey.net/ // @version 0.1 // @description try to take over the world! // @author You // @match https://item.taobao.com/item* // @match https://detail.tmall.com/item* // @grant GM_xmlhttpRequest // @run-at document-idle // @grant GM_setValue // @grant GM_getValue // @grant GM_setClipboard // @grant unsafeWindow // @grant window.close // @grant window.focus // @require https://cdn.bootcss.com/jquery/2.2.4/jquery.js // @grant GM_xmlhttpRequest // ==/UserScript== (function() { 'use strict'; setTimeout(function () { var taobaoGoodUrl = window.location.href; var finalUrl = ""; if(taobaoGoodUrl.indexOf("taobao")>0){ finalUrl = taobaoGoodUrl.replace('https://item.taobao.com/item.htm?', 'https://item.taobao.com/item.htm?abc=1&') } if(taobaoGoodUrl.indexOf("tmall")>0){ finalUrl = taobaoGoodUrl.replace('https://detail.tmall.com/item.htm?', 'https://item.taobao.com/item.htm?abc=1&') } console.log("==============>"); console.log(finalUrl); console.log("==============>"); var taobao_good_id = getQueryString(finalUrl,"id"); getHighRate(taobao_good_id); }, 2000)//隔2秒之后执行.应该就能解决这个问题了 // Your code here... })(); /** * 单个商品获取优惠券高佣数据 * @param taobao_good_id */ function getHighRate(taobao_good_id) { var taobaourl = "https://shaobingquan.com/taobao/getCouponByMoneky?pid=mm_13873584_23600399_359990876&taobao_good_id="+taobao_good_id; GM_xmlhttpRequest({ method: 'GET', url: taobaourl, onload: function(msg){ var json = msg.responseText; console.log(json); var a = eval('(' + json + ')'); var fangQiangFavor = a.result.body; var resultCode = a.result.resultCode; var resultMsg = a.result.resultMsg; var html = new Array(); html.push('<div style="color:#000;background:#FFF2E8;font-size:20px;">'); html.push('<a style="color:#1056f9; font-weight: bold;height: 36px;line-height: 41px;min-width: 100px;display: inline-block;" href=" '); html.push(fangQiangFavor.lovepop_coupon_url); html.push('">'); html.push('点我领券(无券也能拿返佣)</a> </br>'); html.push('<span name="'); html.push('fangyong'); html.push('"'); html.push('>返佣比例:'); html.push(fangQiangFavor.mission_price); html.push('%</span>'); html.push('==>约'); console.log("fangQiangFavor.mission_price======>"+fangQiangFavor.mission_price); console.log("fangQiangFavor.zk_final_price======>"+fangQiangFavor.zk_final_price); var final_price = Number((fangQiangFavor.mission_price*fangQiangFavor.zk_final_price/100)); html.push(final_price); html.push('元</br> <span name="'); html.push('coupon'); html.push('"'); html.push('>优惠券金额:'); html.push(fangQiangFavor.coupon_price); html.push('</span>'); html.push('</div>'); $('#J_isku').append(html.join('')); $('.tb-sku').append(html.join('')); } }); } function getQueryString(url, name) { var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i"); var r = url.substr(1).match(reg); if (r != null) return unescape(r[2]); return null; }
脚本部署步骤:
1、先在chrome中安装tampermonkey
2、在tampermonkey里新建一个用户脚本
3、将上面的代码复制进去保存
4、打开任意淘宝商品,进入详情页,等待2秒,如果没有,那就再打开一个商品试试
如图,说明你成功了。