Greasy Fork

来自缓存

Greasy Fork is available in English.

京东列表js

京东列表文件

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

此脚本不应直接安装。它是供其他脚本使用的外部库,要使用该库请加入元指令 // @require https://update.greasyfork.icu/scripts/441335/1026915/%E4%BA%AC%E4%B8%9C%E5%88%97%E8%A1%A8js.js

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

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

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

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

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

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

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

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

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

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

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

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

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

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

if (host.indexOf("coll.jd") > -1) {
    jdCollInit();
}
if (
    host.indexOf("list.jd") > -1 ||
    host.indexOf("search.jd") > -1
) {
    jdListRec();
    jdListInit();
    jdDropDown();
    jdPageChange();
}
function jdCollInit() {
    let listArr = $("#plist ul").children("li").find(".j-sku-item");
    listArr.each(function () {
        let that = $(this);
        let id = that.attr("data-sku");
        if (id) {
            getJdListCoupon(id);
        }
    });
}
// 下拉改变时触发
function jdDropDown() {
    let node = $("#J_goodsList .gl-warp")[0];
    if (node) {
        domAddEventListener(node, jdDropDownChange);
    }
}
// 下拉回调
function jdDropDownChange(data) {
    let arr = data[0].addedNodes;
    arr.forEach((item) => {
        if (item.nodeName === "LI") {
            let id = $(item).attr("data-sku");
            if (id) {
                getJdListCoupon(id);
            }
        }
    });
}
// 分页改变时触发
function jdPageChange() {
    let node = $(".ml-wrap")[0];
    if (node) {
        domAddEventListener(node, pageChangeCall);
    }
}
// 分页回调
function pageChangeCall(data) {
    data.forEach((item) => {
        if (item.type === "childList") {
            if ($(item.target).attr("class") === "ml-wrap") {
                if (item.addedNodes.length > 8) {
                    jdListInit();
                    jdDropDown();
                }
            }
        }
    });
}
// 列表初始化
function jdListInit() {
    let listArr = $("#J_goodsList ul").children("li");
    listArr.each(function () {
        let that = $(this);
        let id = that.attr("data-sku");
        if (id) {
            getJdListCoupon(id);
        }
    });
}
// 获取列表详情
function getJdListCoupon(id) {
    let params = {
        data: {
            key: id,
        },
    };
    let dtd = $.Deferred();
    let wait = function (dtd) {
        $.ajax({
            url: "https://api.ergirl.com/jdSearch",
            type: "post",
            data: JSON.stringify(params),
            headers: {
                "Content-Type":
                    "application/json; charset=UTF-8",
            },
        })
            .done(function (res) {
                dtd.resolve(res);
            })
            .fail(function () {
                dtd.resolve({ error: true });
            });
        return dtd.promise();
    };
    $.when(wait(dtd)).done(function (res) {
        addjdListCoupon(res);
    });
}
// 添加京东列表优惠券
function addjdListCoupon(res) {
    if (res.data.unionGoods.length === 1) {
        let data = res.data.unionGoods[0][0];
        if (data.couponLink) {
            if (window.location.host.indexOf("coll.jd") > -1) {
                let that = $(
                    '#plist ul li .j-sku-item[data-sku="' +
                    data.skuId +
                    '"]'
                );
                let html =
                    "<div class='jar-list-coupon'><p><a target='_blank'>满" +
                    data.couponQuota +
                    "元减" +
                    data.couponDiscount +
                    "元</a></p></div>";
                that.append(html);
            } else {
                let that = $(
                    '#J_goodsList ul li[data-sku="' +
                    data.skuId +
                    '"]'
                );
                let html =
                    "<div class='jar-list-coupon'><p><a target='_blank'>满" +
                    data.couponQuota +
                    "元减" +
                    data.couponDiscount +
                    "元</a></p></div>";
                that.append(html);
            }
        }
    }
}
// 京东列表推荐
function jdListRec() {
    let params = {
        pageNo: 1,
        pageSize: 50,
        data: {
            hasCoupon: 1,
            cat3Id: LogParm.rel_cat3.split(",")[0],
        },
    };
    let dtd = $.Deferred();
    let wait = function (dtd) {
        $.ajax({
            url: "https://api.ergirl.com/jdSearch",
            type: "post",
            data: JSON.stringify(params),
            headers: {
                "Content-Type":
                    "application/json; charset=UTF-8",
            },
        })
            .done(function (res) {
                dtd.resolve(res);
            })
            .fail(function () {
                dtd.resolve({ error: true });
            });
        return dtd.promise();
    };
    $.when(wait(dtd)).done(function (res) {
        addJdListRec(res);
    });
}
// 增加京东列表推荐
function addJdListRec(data) {
    let html = "";
    let mainHtml = "";
    let startHtml =
        '<div class="goods-list-v2">' +
        '<ul class="gl-warp clearfix">' +
        '<div class="swiper-container">' +
        '<div class="swiper-wrapper">';
    let endHtml =
        '</div><div class="swiper-button-prev" style="width:45px;height:100px;color: #f40;margin-top:-50px;background:rgba(0,0,0,0.4)"></div><div class="swiper-button-next" style="width:45px;height:100px;color: #f40;margin-top:-50px;margin-right: 20px;background:rgba(0,0,0,0.4);"></div></div></ul>' +
        "</div>";
    let arr = data.data.unionGoods;
    arr.forEach((item) => {
        let html1 =
            '<div class="swiper-slide">' +
            '<li data-sku="' +
            item[0].skuId +
            '" class="gl-item" style="height: 380px;float:left;">' +
            '<div class="gl-i-wrap">' +
            '<div class="p-img">' +
            '<a rel=noreferrer target="_blank" href="//item.jd.com/' +
            item[0].skuId +
            '.html">' +
            '<img width="220" height="220" src=//img11.360buyimg.com/n7/' +
            item[0].materialUrl +
            ">" +
            "</a>" +
            "</div>" +
            '<div class="p-price">' +
            '<strong class="J_1026563726">' +
            "<em>¥</em><i>" +
            item[0].lowerPrice +
            "</i>" +
            "</strong>" +
            "</div>" +
            '<div class="p-name p-name-type-3" style="height: 22px;">' +
            '<a rel=noreferrer target="_blank" href="//item.jd.com/' +
            item[0].skuId +
            '.html">' +
            "<em>" +
            item[0].skuName +
            "</em>" +
            "</a>" +
            "</div>" +
            '<div class="p-shop">' +
            '<span class="J_im_icon"><a target="_blank" class="curr-shop hd-shopname" title="' +
            item[0].shopName +
            '">' +
            item[0].shopName +
            "</a></span>" +
            "</div>" +
            "</div>" +
            "<div class='jar-list-coupon' style='right:15px;bottom:0;'><p><a target='_blank'>满" +
            item[0].couponQuota +
            "元减" +
            item[0].couponDiscount +
            "元</a></p>" +
            "</li>" +
            "</div>";
        mainHtml += html1;
        jdListChangeUrl(item[0].skuId);
    });
    html = startHtml + mainHtml + endHtml;
    let that = $("#J_main .m-list #J_filter");
    that.before(html);
    var mySwiper = new Swiper(".swiper-container", {
        slidesPerView: 5,
        slidesPerGroup: 5,
        navigation: {
            nextEl: ".swiper-button-next",
            prevEl: ".swiper-button-prev",
        },
    });
}
// 京东转链
function jdListChangeUrl(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 url = "https://www.ergirl.com/qq/api";
    dtd(url, params, jdRecUrl, id);
}
// 插入链接
function jdRecUrl(res, id) {
    let result = JSON.parse(res).jd_union_open_promotion_common_get_response
        .result;
    let obj = JSON.parse(result).data;
    $(".swiper-slide li[data-sku=" + id + "]")
        .find("a")
        .attr(
            "href",
            "http://quan.ergirl.com/jump.html?url=" +
            encodeURIComponent(obj.clickURL)
        );
}