Greasy Fork

Greasy Fork is available in English.

AC-淘宝天猫商品优惠信息查询

淘宝天猫商品查询是否具有优惠券

当前为 2017-11-10 提交的版本,查看 最新版本

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         AC-淘宝天猫商品优惠信息查询
// @version      2.4
// @description  淘宝天猫商品查询是否具有优惠券
// @author       AC
// @include      https://item.taobao.com/item.htm*
// @include      https://detail.tmall.com/item.htm*
// @include      https://s.taobao.com/search?q=*
// @note         2017.11.10-V2.4 如果有优惠,可以展示出优惠信息了
// @note         2017.11.4-V2.3 暂时新增两种模式供选择
// @note         2017.11.2-V2.2 参照了一个大神的脚本之后拿到了一些css,于是又加了些东西,展示一些双十一相关的标签
// @note         2017.11.1-V2.1 切换为include规则,而非match规则,避免GreaseMonkey上无法使用的问题
// @note         2017.10.30-V2.0 修复在某些页面上,标题获取不正确的问题
// @note         2017.10.28-V1.0 第一版本,edit from http://greasyfork.icu/zh-TW/scripts/34604
// @icon         https://coding.net/u/zb227/p/zbImg/git/raw/master/img0/icon.jpg
// @home-url     http://greasyfork.icu/zh-TW/scripts/34606
// @run-at       document-start
// @namespace    [email protected]
// @require      https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js
// ==/UserScript==
// .tb-detail-hd, .tb-main-title
var acJquery = jQuery.noConflict();
function AutoStart(time, cssSelector, dealFunc) {
    var timerNode = setInterval(function () {
        if (document.querySelector(cssSelector).style.display == "") {
            clearInterval(timerNode);
            dealFunc();
        }
    }, time);
}
function getQueryString(name) {
    var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
    var r = window.location.search.substr(1).match(reg);
    if (r != null) return unescape(r[2]); return null;
}
function addStyle(css) { //添加CSS的代码--copy的
    var pi = document.createProcessingInstruction(
        'xml-stylesheet',
        'type="text/css" href="data:text/css;utf-8,' + encodeURIComponent(css) + '"'
    );
    return document.insertBefore(pi, document.documentElement);
}
function acBuyScript(result){
    var node = document.querySelector(".acBuyScriptCoupon");
    if(result.count == 1){
        node.innerHTML = "!有优惠券啊!";
        node.href = "https://s.click.taobao.com/" + result.mod_json_details.couponUrl;
    }else{
        node.innerHTML = "已领取或无优惠"
    }
}
if (location.host == "item.taobao.com" || location.host == "detail.tmall.com") {
    AutoStart(200, ".tb-detail-hd, .tb-main-title", function () {
        var TitleNode = document.querySelector("div#J_Title h3, div.tb-detail-hd h1");
        var goodTitle = TitleNode.lastChild.nodeValue.trim();
        var goodID = getQueryString("id");
        var queryCoupon = "https://www.ntaow.com/details.jsp?auctionId=" + goodID;
        var querySimilar = "https://www.ntaow.com/coupon.jsp?mQuery=" + encodeURI(goodTitle);
        var faNode = document.querySelector("div#J_Title p.tb-subtitle, div.tb-detail-hd h1");
        var insNode = document.createElement("div");
        insNode.style = "font-size: 32px;font-weight: bold;font-family:microsoft yahei;";
        var htmlText = "<a class='acBuyScriptCoupon' href='javascript:void(0);' style='color: red;'>==找优惠==</a>";
        htmlText += "&nbsp;&nbsp;&nbsp;&nbsp;<a href=" + querySimilar + " target='_blank' style='color: red;'>==找相似==</a>";
        insNode.innerHTML = htmlText;
        faNode.appendChild(insNode);
        setTimeout(function(){
            acJquery.ajax({
                url:"https://www.ntaow.com/getDetails_json.jsp?auctionId="+goodID,
                dataType:'jsonp',
                success:function(result) {
                    console.log(result);
                },
                timeout:3000
            });
        }, 200);
        var jsNode = document.createElement("script");
        jsNode.innerHTML = "function acBuyScript(result){\n" +
            "    var node = document.querySelector(\".acBuyScriptCoupon\");\n" +
            "    if(result.count == 1){\n" +
            "        node.innerHTML = \"!有优惠券啊!\";\n" +
            "        node.href = \"https://s.click.taobao.com/\" + result.mod_json_details.couponUrl;\n" +
            "    }else{\n" +
            "        node.innerHTML = \"无优惠信息\"\n" +
            "        node.style = \"font-size: 11px;\";\n" +
            "    }\n" +
            "}";
        document.body.appendChild(jsNode);
    });
} else if (location.host == "s.taobao.com") {
    AutoStart(200, ".m-itemlist", function () {
        addStyle(".m-itemlist .grid .row-4 { margin-top: 1px !important; margin-bottom: 20px;}");
        addStyle('.m-itemlist .grid .row-4, .m-itemlist .icon-has-more { overflow: visible !important;}');
        addStyle(".m-itemlist .grid .item { height: 376px !important;}");
        addStyle(".m-itemlist .grid .icon { margin-top: 3px; !important;}");
        addStyle(".grid .item-ctx-hover .icons { margin-top: 7px !important;}");

        addStyle(".response-wider  .m-itemlist .grid .item { height: 406px !important}");
        addStyle(".response-narrow  .m-itemlist .grid .item { height: 336px !important}");
    });
}