Greasy Fork

来自缓存

Greasy Fork is available in English.

京东详情js

京东详情文件

当前为 2022-03-11 提交的版本,查看 最新版本

此脚本不应直接安装。它是供其他脚本使用的外部库,要使用该库请加入元指令 // @require https://update.greasyfork.icu/scripts/441336/1026908/%E4%BA%AC%E4%B8%9C%E8%AF%A6%E6%83%85js.js

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

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

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

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

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

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

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

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

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

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

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

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

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

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

let host = window.location.host;

$(function () {
    if (host.indexOf("item.jd.com") > -1) {
        initJdDetail();
        addJdBasic();
    }
});
// 京东详情初始化入口
function initJdDetail() {
    if (host.indexOf("item.jd.com") > -1) {
        let id = window.location.pathname;
        let index = id.lastIndexOf("/");
        id = id.substring(index + 1, id.length);
        id = id.match(/(\S*).html/)[1];
        getJdDetail(id);
        likeJd();
        getJdHistory();
    }
}
//获取京东商品信息;
function getJdDetail(id) {
    let url = "https://api.ergirl.com/jdData";
    let params = {
        id: id,
    };
    dtd(url, params, addJdCoupon);
}
// 插入京东优惠券
function addJdCoupon(data) {
    let arr = data.data.list;
    if (arr.length > 0 && arr[0].couponInfo.couponList.length > 0) {
        let changeUrl = jdChangeUrl(
            arr[0].skuId,
            arr[0].couponInfo.couponList[0].link
        );
        let coupon = arr[0].couponInfo.couponList[0];
        let result = JSON.parse(changeUrl)
            .jd_union_open_promotion_common_get_response.result;
        let obj = JSON.parse(result).data;
        let clickURL = "";
        if (JSON.parse(result).code === 200) {
            clickURL = obj.clickURL;
        } else {
            clickURL = coupon.link;
        }
        let html =
            '<a rel=noreferrer href="' +
            clickURL +
            '" target="_blank"><div class="jar-body-coupon-left">满' +
            coupon.quota +
            "元减" +
            coupon.discount +
            "元" +
            "</div></a>" +
            '<div div class="jar-body-coupon-center">' +
            "<div>使用开始时间: <span>" +
            timeFormat(coupon.useStartTime, 1) +
            "</span></div>" +
            "<div>使用结束时间: <span>" +
            timeFormat(coupon.useEndTime, 1) +
            "</span></div>" +
            "</div >" +
            '<div class="jar-button"><a rel=noreferrer href="' +
            clickURL +
            '" target="_blank">点击领取</a></div>';
        $(".jar-body-coupon-top").append(html);
    } else {
        let changeUrl = jdChangeUrl(arr[0].skuId);
        let result = JSON.parse(changeUrl)
            .jd_union_open_promotion_common_get_response.result;
        let obj = JSON.parse(result).data;
        let html =
            '<div class="getAgain">' +
            '<div class="again-box">' +
            '<img src="https://gw.alicdn.com/tps/TB11KWxOVXXXXXHXXXXXXXXXXXX-190-150.png" alt="">' +
            "<p>正在查询...</p>" +
            "<p>随后将返回详情页</p>" +
            "</div>" +
            "</div>" +
            '<div class="jar-body-coupon-left">当前商品暂无优惠券</div>' +
            '<div div class="jar-body-coupon-center">' +
            "<div>使用开始时间: <span>0</span></div>" +
            "<div>使用结束时间: <span>0</span></div>" +
            "</div >" +
            '<div class="jar-button"><a data-href="' +
            obj.clickURL +
            '" target="_blank">深度查询</a></div>';
        $(".jar-body-coupon-top").append(html);
        $(".jar-button").click(function () {
            $(".getAgain").show();
            setTimeout(() => {
                $(".getAgain").hide();
                let url = $(this).find("a").attr("data-href");
                redirect(url);
            }, 1000);
        });
    }
}
// 获取相似比价
function likeJd() {
    let goodsReq = {
        eliteId: 2,
        hasCoupon: 1,
        siteId: "4000380964",
    };
    let params = {
        v: "1.0",
        method: "jd.union.open.goods.material.query",
        app_key: "749ec5acf07b3bc2c623a465bc77c0e4",
        sign_method: "md5",
        format: "json",
        timestamp: dateFormat(),
        param_json: JSON.stringify({
            goodsReq: goodsReq,
        }),
    };
    let obj = objKeySort(params);
    let secretkey = "de15ce50b876430b941d3d9d5f307c2b";
    let str = "";
    for (i in obj) {
        if (
            params[i] !== "" &&
            params[i] !== null &&
            params[i] !== undefined
        ) {
            str += i + params[i];
        }
    }
    params.sign = md5(secretkey + str + secretkey).toUpperCase();
    let url = "https://www.ergirl.com/qq/api";
    dtd(url, params, addJdLike);
}
// 插入相似
function addJdLike(data) {
    let result = JSON.parse(data)
        .jd_union_open_goods_material_query_response.result;
    let obj = JSON.parse(result).data;
    obj.forEach((item) => {
        let html =
            "<dl>" +
            '<dd><a rel=noreferrer href="' +
            item.promotionInfo.clickURL +
            '" target="_blank">' +
            '<div class="img">' +
            '<img src="' +
            item.imageInfo.imageList[0].url +
            '" alt="">' +
            "</div>" +
            '<div class="infor" >' +
            "<div>价格: <span>" +
            item.priceInfo.price +
            "</span></div>" +
            '<div class="jar-like-coupon">优惠券: <span>' +
            item.couponInfo.couponList[0].discount +
            "</span></div>" +
            "</div>" +
            '<div class="clear"></div>' +
            '<div class="title">' +
            item.skuName +
            "</div>" +
            "</a></dd>" +
            "</dl>";
        $(".jar-like-list").append(html);
    });
}
// 获取历史记录
function getJdHistory() {
    let id = window.location.pathname;
    let index = id.lastIndexOf("/");
    id = id.substring(index + 1, id.length);
    id = id.match(/(\S*).html/)[1];
    let url = "https://api.ergirl.com/gwdang/trend/data_www";
    let params = {
        dp_id: id + "-3",
        v: 2,
    };
    let arr = [];
    $.ajax({
        url: url,
        data: params,
        type: "get",
        success: function (res) {
            let obj = JSON.parse(res).promo_detail;
            obj.forEach((item) => {
                let o = {
                    time: timeFormat(item.time * 1000, 1),
                    ori_price: item.ori_price / 100,
                    price: item.price / 100,
                    msg: item.msg[0].text,
                };
                arr.push(o);
            });
            let max = JSON.parse(res).promo_series[0].max / 100;
            let min = JSON.parse(res).promo_series[0].min / 100;
            addJdHistory(arr, max, min);
        },
    });
}
// 插入历史价格
function addJdHistory(data, max, min) {
    let ori_price = [];
    let time = [];
    data.forEach((item) => {
        ori_price.push(item.ori_price);
        time.push(item.time);
    });
    let seriesData = {
        historyPrice: ori_price,
        time: time,
    };
    seriesData.minNum = min;
    seriesData.maxNum = max;
    console.log(seriesData);
    eachart(seriesData);
}
// 插入基本元素
function addJdBasic() {
    let html =
        '<div class="jar-detail-coupon">' +
        '<div class="jar-tab" >' +
        "<ul>" +
        '<li class="active">领券</li>' +
        "<li>实时热销</li>" +
        "<li>价格趋势</li>" +
        '</ul><span class="jar-show">隐藏</span>' +
        "</div >" +
        '<div class="jar-body">' +
        "<ul>" +
        "<li>" +
        '<div class="jar-body-coupon">' +
        '<div class="jar-body-coupon-top"></div>' +
        '<div class="clear"></div>' +
        '<div class="jar-body-coupon-right">温馨提示: <span><a href="https://www.ergirl.com" target="_blank">点击查询更多优惠券</a></span></div>' +
        "</div>" +
        "</li>" +
        "<li>" +
        '<div class="jar-like-list">' +
        "</div> " +
        "</li>" +
        "<li>" +
        '<div class="jar-history">' +
        '<div id="historyChart" style="width: 468px; height: 300px;"></div>' +
        "</div>" +
        "</li>" +
        "</ul>" +
        "</div>" +
        "</div >";
    if (host.indexOf("jd") > -1) {
        // 插入淘宝
        $("#J-summary-top").append(html);
    }
    $(".jar-detail-coupon .jar-tab li").click(function () {
        let index = $(this).index();
        $(".jar-detail-coupon .jar-tab li").removeClass("active");
        $(this).addClass("active");
        $(".jar-detail-coupon .jar-body li").hide();
        $(".jar-detail-coupon .jar-body li").eq(index).show();
    });
    $(".jar-show").click(function () {
        if ($(".jar-show").html() == "隐藏") {
            $(".jar-show").html("展开");
        } else {
            $(".jar-show").html("隐藏");
        }
        $(".jar-detail-coupon .jar-body").toggle();
    });
}
// 京东转链
function jdChangeUrl(id, cUrl) {
    let mid = "https://item.jd.com/" + id + ".html";
    let promotionCodeReq = {
        materialId: mid,
        siteId: "4000380964",
    };
    if (cUrl) {
        promotionCodeReq.couponUrl = cUrl;
    }
    let params = {
        v: "1.0",
        method: "jd.union.open.promotion.common.get",
        app_key: "749ec5acf07b3bc2c623a465bc77c0e4",
        sign_method: "md5",
        format: "json",
        timestamp: dateFormat(),
        param_json: JSON.stringify({
            promotionCodeReq: promotionCodeReq,
        }),
    };
    let obj = objKeySort(params);
    let secretkey = "de15ce50b876430b941d3d9d5f307c2b";
    let str = "";
    for (i in obj) {
        if (
            params[i] !== "" &&
            params[i] !== null &&
            params[i] !== undefined
        ) {
            str += i + params[i];
        }
    }
    params.sign = md5(secretkey + str + secretkey).toUpperCase();
    let data = {};
    $.ajax({
        url: "https://www.ergirl.com/qq/api",
        method: "get",
        async: false,
        data: params,
        success: function (res) {
            data = res;
        },
    });
    return data;
}