frinkyu / 淘宝天猫购物优惠券 搜券助手 省钱必备工具

// ==UserScript==
// @namespace    https://openuserjs.org/user/skypesky
// @name         淘宝天猫购物优惠券 搜券助手 省钱必备工具
// @author       frinkyu
// @collaborator liang
// @copyright    2018, skypesky (https://openuserjs.org/users/skypesky)
// @version      18.09.14
// @description  [skypesky 出品]支持手机扫描二维码领取优惠券 淘宝天猫购物优惠券 优惠券 省钱必备工具 最新版(2018-09-14) 

// @license Apache-2.0

// @connect      *
// @grant        GM_getResourceText
// @grant        GM_addStyle


// ==========================详情页===========================
// @include      http*://s.taobao.com/search*
// @include      http*://list.tmall.com*
// @include      http*://list.tmall.hk/search_product.htm*
// @include      http*://www.tmall.com/*

// ==========================搜索页============================
// @include      http*://item.taobao.com/*
// @include      http*://detail.tmall.com/*
// @include      http*://chaoshi.detail.tmall.com/*
// @include      http*://detail.tmall.hk/*
// @include      http*://detail.yao.95095.com/item.htm*

// ==========================资源============================
// @resource     toastr https://cdn.bootcss.com/izitoast/1.3.0/css/iziToast.min.css
// @resource     contexMenu https://cdn.bootcss.com/jquery-contextmenu/2.6.1/jquery.contextMenu.min.css


// ==========================js============================
// @require      https://cdn.bootcss.com/jquery/3.3.1/jquery.min.js
// @require      https://cdn.bootcss.com/jquery.qrcode/1.0/jquery.qrcode.min.js
// @require      https://cdn.bootcss.com/jquery-cookie/1.4.1/jquery.cookie.js
// @require      https://cdn.bootcss.com/jquery-contextmenu/2.6.1/jquery.contextMenu.min.js
// @require      https://cdn.bootcss.com/izitoast/1.3.0/js/iziToast.min.js


// ==/UserScript== 
(function () {
    'use strict';
    $(document).ready(function () {
        var host = window.location.host;
        var productNm = '';
        var url = "http://www.r10263.cn/mall/topic?type=4&isc=0&goodSource=1&sign=KY58&title=9.9%E5%8C%85%E9%82%AE";
         var urll = "http://www.r10263.cn/mall/?sign=KY58";
        var label = "精选9.9包邮";
        var labell = "获取优惠劵";
        var cssSelector = '';
        if (host.indexOf('taobao.com') > 0) {
            productNm = $.trim($('.tb-main-title').text());
            cssSelector = '.tb-action';
        } else if (host.indexOf('tmall.com') > 0) {
            productNm = $.trim($('.tb-detail-hd h1').text());
            cssSelector = '.tb-action';
        } else if (host.indexOf('jd.com') > 0) {
            productNm = $.trim($('.sku-name').text());
            cssSelector = '#choose-btns';
            url = "http://www.r10263.cn/mall/?sign=KY58";
        }
        $(cssSelector).append(obtainAppendHtml(host, url, productNm, label, urll, labell));
    });

    function obtainAppendHtml(host, url, productNm, label, urll, labell) {
        if (host.indexOf('taobao.com') > 0) {
            return '<div class="div-inline"><div class="tb-btn-buy" style="padding-top:11px;"><a href="' + url + encodeURI(productNm) + '" target="_blank">' + label + '</a></div></div> <div class="div-inline"><div class="tb-btn-add" style="padding-top:11px;"><a href="' + urll + '" target="_blank">' + labell + '</a></div></div>';
        } else if (host.indexOf('tmall.com') > 0) {
            return '<div class="div-inline"><div class="tb-btn-buy tb-btn-sku"  style="padding-top:11px;"><a href="' + url + encodeURI(productNm) + '" target="_blank">' + label + '</a></div></div> <div class="div-inline"><div class="tb-btn-basket tb-btn-sku " style="padding-top:11px;"><a href="' + urll + '" target="_blank">' + labell + '</a></div></div>';
        } else if (host.indexOf('jd.com') > 0) {
            return '<a class="btn-special1 btn-lg" href="' + url + encodeURI(productNm) + '" target="_blank">' + label + '</a>';
        }
    }
})();
(function() {
    $(document).ready(function() {
		var url = window.location.host;
        var itemName = '';//$(document).attr('title');
        var itemId = window.location.href.split("id=")[1].split('&')[0];
        var faNode = document.querySelector("div#J_Title p.tb-subtitle, div.tb-detail-hd");
		if (url == 'item.taobao.com') {
            itemName = $('.tb-main-title').attr('data-title');
            var btn_quan_taobao = '<a style="display: inline-block;padding: 6px 12px;margin-bottom: 0;font-size: 14px;font-weight: normal;height:26px;line-height:26px;text-align: center;white-space: nowrap;vertical-align: middle;-ms-touch-action: manipulation;touch-action: manipulation;cursor: pointer;-webkit-user-select: none;-moz-user-select: none;-ms-user-select: none;user-select: none;background-image: none;border: 1px solid transparent;border-radius:2px;color: #fff;background-color: #DF231C;#FF0036;margin-left:10px" href="http://www.r10263.cn/mall/findResult?spm=a220o.1000855.0.0.315b4fa5NNOyl8&sign=KY58&goodSource=1&keyword='+ encodeURI(itemName) +'&id='+ encodeURI(itemId) +'" " target="_blank">领取优惠券</a>';
            $('.tb-action').append(btn_quan_taobao);
		}else if(url == 'detail.tmall.com'){
            itemName = $('meta[name=keywords]').attr('content');
            var btn_quan_tmall =   '<div class="tb-action" style="margin-top:0"><a style="display: inline-block;padding: 6px 12px;margin-bottom: 0;font-size: 14px;font-weight: normal;height:26px;line-height:26px;width:156px;text-align: center;white-space: nowrap;vertical-align: middle;-ms-touch-action: manipulation;touch-action: manipulation;cursor: pointer;-webkit-user-select: none;-moz-user-select: none;-ms-user-select: none;user-select: none;background-image: none;border: 1px solid transparent;border-radius:2px;color: #fff;background-color: #DF231C;#FF0036;" href="http://www.r10263.cn/mall/findResult?spm=a220o.1000855.0.0.315b4fa5NNOyl8&sign=KY58&goodSource=1&keyword='+ encodeURI(itemName) +'&id='+ encodeURI(itemId) +'" " target="_blank">领取优惠券</a></div>';
			$('.tb-sku').append(btn_quan_tmall);
        }else if(url == 'chaoshi.detail.tmall.com'){
            itemName = $('input[name=title]').attr('value');
            var btn_chaoshi_tmall = '<div class="tb-action tb-btn-add tb-btn-sku"><a href="http://www.r10263.cn/mall/findResult?spm=a220o.1000855.0.0.315b4fa5NNOyl8&sign=KY58&goodSource=1&keyword='+ encodeURI(itemName) +'&id='+ encodeURI(itemId) +'" " target="_blank">领取优惠券</a></div>'
            $('.tb-sku').append(btn_chaoshi_tmall);
        }else if(url == 'detail.tmall.hk'){
            itemName = $('meta[name=keywords]').attr('content');
            var btn_tmall_hk =   '<div class="tb-action" style="margin-top:0"><a style="display: inline-block;padding: 6px 12px;margin-bottom: 0;font-size: 14px;font-weight: normal;height:26px;line-height:26px;width:156px;text-align: center;white-space: nowrap;vertical-align: middle;-ms-touch-action: manipulation;touch-action: manipulation;cursor: pointer;-webkit-user-select: none;-moz-user-select: none;-ms-user-select: none;user-select: none;background-image: none;border: 1px solid transparent;border-radius:2px;color: #fff;background-color: #DF231C;#FF0036;" href="http://www.r10263.cn/mall/findResult?spm=a220o.1000855.0.0.315b4fa5NNOyl8&sign=KY58&goodSource=1&keyword='+ encodeURI(itemName) +'&id='+ encodeURI(itemId) +'" " target="_blank">领取优惠券</a></div>';
			$('.tb-sku').append(btn_tmall_hk);
        }
    });
})();