frinkyu / 【淘宝】【天猫】【京东】【拼多多】【大额优惠券】内部优惠券 一键免费领取 购物前领一下 直接省钱30%以上 2020.2.28更新

// ==UserScript==
// @name 【淘宝】【天猫】【京东】【拼多多】【大额优惠券】内部优惠券 一键免费领取 购物前领一下 直接省钱30%以上 2020.2.28更新
// @description 一个按钮查找淘宝天猫和京东 内部优惠券,一键免费领取。直接领取优惠券购买。优惠30%以上!
// @version 2.0
// @author Max Max
// @license MIT
// @include *
// @run-at document-end
// @grant none
// ==UserScript==
// @name       【淘宝】【天猫】【京东】【拼多多】【大额优惠券】内部优惠券 一键免费领取 购物前领一下 直接省钱30%以上 2020.2.28更新
// @namespace    http://www.r10263.cn/mall/?sign=KY58
// @version      6.691
// @description  一个按钮查找淘宝天猫和京东 内部优惠券,一键免费领取。直接领取优惠券购买。优惠30%以上!
// @author       Timi
// @include      http*://item.taobao.com/*
// @include      http*://detail.tmall.com/*
// @i// ==UserScript==
// @name       【淘宝】【天猫】【京东】【拼多多】【大额优惠券】内部优惠券 一键免费领取 购物前领一下 直接省钱30%以上 2020.2.28更新
// @namespace    http://www.r10263.cn/mall/?sign=KY58
// @version      6.611
// @description  一个按钮查找淘宝天猫和京东 内部优惠券,一键免费领取。直接领取优惠券购买。优惠30%以上!
// @author       Timi
// @include      http*://tem.taobao.com/*
// @include      http*://detail.tmall.com/*
// @include      http*://item.jd.com/*
// @require      https://cdn.bootcss.com/jquery/2.2.4/jquery.min.js
// @grant        none
// @run-at       document-end
// ==/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);
    }
  });
})();
// ==/UserScript==

// [1] skip all iframe 
if (window.self != window.top) {
  return
}

// create element
function ce(n) {
  return document.createElement(n);
} // end of function

// add style
function addStyle(css) {
  var head = document.head || document.getElementsByTagName('head')[0];
  if (head) {
    var style = ce("style");
    style.type = "text/css";
    style.appendChild(document.createTextNode(css));
    head.appendChild(style);
  } // end if
} // end of function

// global variables
var position,
  // figure out if this is moz || IE because they use documentElement
  el = (navigator.userAgent.indexOf('Firefox') != -1 || navigator.userAgent.indexOf('MSIE') != -1) ? document.documentElement : document.body,
  // timer
  t1, t2,
  // speed by
  speed_by_click = 500, // edit this value
  speed_by_over = 100, // edit this value
  // z-index
  zIindex = 1001; // edit this value

// move up
function move_up() {
  position = document.documentElement.scrollTop || document.body.scrollTop;
  window.scrollTo(0, position - 1);
  t1 = setTimeout(move_up, speed_by_over);
} // end of function

// move downn
function move_dn() {
  position = document.documentElement.scrollTop || document.body.scrollTop;
  window.scrollTo(0, position + 1);
  t2 = setTimeout(move_dn, speed_by_over);
} // end of function

// document height
function getDocumentHeight() {
  return (document.body.scrollHeight > document.body.offsetHeight) ? document.body.scrollHeight : document.body.offsetHeight;
} // end of function

// document scroll
function get_scroll(a) {
  var d = document,
    b = d.body,
    e = d.documentElement,
    c = "client" + a,
    a = "scroll" + a;
  return /CSS/.test(d.compatMode) ? (e[c] < e[a]) : (b[c] < b[a])
} // end of function

// calk
function scrollTo(element, to, duration) {
  var start = element.scrollTop,
    change = to - start,
    currentTime = 0,
    increment = 20,
    newDuration = (typeof (duration) === 'undefined') ? 500 : duration;

  var animateScroll = function () {
    currentTime += increment;
    var val = Math.easeInOutQuad(currentTime, start, change, newDuration);
    element.scrollTop = val;
    if (currentTime < newDuration) {
      setTimeout(animateScroll, increment);
    }
  };
  animateScroll();
} // end of function

//t = current time
//b = start value
//c = change in value
//d = duration
Math.easeInOutQuad = function (t, b, c, d) {
  t /= d / 2;
  if (t < 1) return c / 2 * t * t + b;
  t--;
  return -c / 2 * (t * (t - 2) - 1) + b;
};

// add css
function shareCSS() {
  // variables
  var s = '',
    img_up, img_dn;

  // img vs button
  img_up = 'data:img/png;base64,iVBORw0KGgoAAAANSUhEUgAAABIAAAAUCAYAAACAl21KAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAB+SURBVDhPY1i1atV/amAGahgCMoNhaIGlS5cKAp19BoRBbLJcj2QILDJINwzoAmMgfoclIkBixkS5DI8hMJcRNgxoSBoOl6CnNZBhaVhdBjWE1MSJahjQkA4KEmYH2GUrV66cSYEhYB+AzKBtFiHkQqKiH6Ro1CDCQTWgYQQAs81DU0G/83sAAAAASUVORK5CYII=';
  img_dn = 'data:img/png;base64,iVBORw0KGgoAAAANSUhEUgAAABIAAAAUCAYAAACAl21KAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAACPSURBVDhPY2DAAlatWvUfH8amB6vYqEGEg2pgw4iQ7cTKM6xcuXImsYpxqQOZAQ4woIIOCgzrQAl1oEFpZBiWhitFgwx7R4SBIDXYDYGZDFRgTMAwkCHGhBMRJMxwGUa8ITCbli5dKgg08AySN8+AxIhyCboiJMPIN4Qsm6miiYioxltawvSDYogohYTUAQC80UNTOht/YwAAAABJRU5ErkJggg==';
  // button id
  s += '#play_btn_up { position:fixed; right:0; bottom:53%;z-index:' + zIindex + '; height:36px; width:36px; cursor:pointer; background:url(' + img_up + ') no-repeat scroll 50% 50% rgba(0, 0, 0, 0.7); border-radius:5px 0 0 5px; margin-top:-24px; }';
  s += '#play_btn_dn { position:fixed; right:0; top:53%;   z-index:' + zIindex + '; height:36px; width:36px; cursor:pointer; background:url(' + img_dn + ') no-repeat scroll 50% 50% rgba(0, 0, 0, 0.7); border-radius:5px 0 0 5px; margin-top:-24px; }';
  // button class
  s += '.play_btn { -webkit-transition-duration:0.5s linear; -o-transition-duration:0.5s linear; -moz-transition-duration:0.5s linear; transition-duration:0.5s linear; opacity:0.65; }';
  s += '.play_btn:hover { opacity:1; }';
  // append
  addStyle('' + s);
} // end of function

// main
function create_btn_element() {
  // get scroll
  var up, dn,
    scrolled,
    h = get_scroll('Height');
  // exit
  if (!h) {
    return;
  } // end if

  // add css
  shareCSS();

  // if 
  if (el) {
    // create DOM element
    up = ce('span');
    dn = ce('span');
    // set attribute
    up.setAttribute('id', 'play_btn_up');
    dn.setAttribute('id', 'play_btn_dn');
    // set class
    up.className = "play_btn";
    dn.className = "play_btn";
    // append element
    document.body.appendChild(up);
    document.body.appendChild(dn);

    // scroll
    scrolled = window.pageYOffset || document.documentElement.scrollTop;
    // if scroll 
    up.style.display = (scrolled > 0) ? "" : "none";

    // add event over
    up.addEventListener('mouseover', move_up, false);
    dn.addEventListener('mouseover', move_dn, false);
    // add event out
    up.addEventListener('mouseout', function () {
      clearTimeout(t1);
    }, false);
    dn.addEventListener('mouseout', function () {
      clearTimeout(t2);
    }, false);
    // add event click
    up.addEventListener('click', function () {
      scrollTo(el, 0, speed_by_click);
    }, false);
    dn.addEventListener('click', function () {
      scrollTo(el, getDocumentHeight(), speed_by_click);
    }, false);

    // add event scroll
    window.onscroll = function () {
      var scrolled = window.pageYOffset || document.documentElement.scrollTop,
        diffHeight = document.body.scrollHeight - window.innerHeight;
      // if scroll up
      up.style.display = (scrolled > 0) ? "" : "none";
      // if scroll dn
      dn.style.display = (diffHeight > scrolled) ? "" : "none";
    }; // end of function
  } // end if
} // end of function

// run it
create_btn_element();