// ==UserScript==
// @name 京淘购物助手【京东版】
// @namespace https://www.jingtaozhushou.com/plugin?from=monkey
// @icon https://www.jingtaozhushou.com/favicon.ico
// @version 1.0.0
// @run-at document-end
// @description 京淘购物助手【京东版】是京淘助手简版,支持查询京东佣金比例、隐藏联盟券、真实库存、企业帐号价格、微信端和手Q端价格查询等;更多功能持续开发中,要使用完整版,请到官网下载!官方交流和反馈QQ群:633824817 问题反馈:https://www.jingtaozhushou.com/feedback?from=monkey
// @description:zh-CN 京淘购物助手【京东版】是京淘助手简版,支持查询京东佣金比例、隐藏联盟券、真实库存、企业帐号价格、微信端和手Q端价格查询等;更多功能持续开发中,要使用完整版,请到官网下载!官方交流和反馈QQ群:633824817 问题反馈:https://www.jingtaozhushou.com/feedback?from=monkey
// @author jingtaozhushou.com
// @require https://cdn.bootcss.com/jquery/2.2.4/jquery.min.js
// @include https://*.jingtaozhushou.com/*
// @include *://*.jd.com/*
// @include *://*.paipai.com/*
// @include *://*.jd.hk/*
// @include *://*.yiyaojd.com/*
// @include *://*.jkcsjd.com/*
// @grant GM_xmlhttpRequest
// @grant GM_log
// @connect 3.cn
// @connect jd.com
// @connect jingtaozhushou.com
// @update 2020-08.01
// ==/UserScript==
(function() {
let gm_info = GM_info.script;
console.log('%c京淘购物助手%c 欢迎您使用京淘助手油猴脚本【京东版】,脚本已加载成功!%c 版本:' + gm_info.version + ' %c Copyright © 2019-' + (new Date).getFullYear() + ' 京淘助手 jingtaozhushou\r.com all rights reserved.', 'background: #030307;color: #fadfa3;font:12px Microsoft YaHei;padding:10px 15px;', 'background: #fadfa3;color:#030307;font:12px Microsoft YaHei;padding:10px 15px;', 'background:#fff5bf;color:#8b7442;font:12px Microsoft YaHei;padding:10px 15px;', 'background:#fffbe5;color:#8b7442; font:12px Microsoft YaHei;padding:10px 15px;', );
let domain = "https://www.jingtaozhushou.com";
let jtzs = {
init: function() {
let _this = this;
this.getCommssion();
this.getJdPcPrice();
this.getRealStock();
setTimeout(function() {
_this.getCompanyPrice();
_this.getWqsPrice()
}, 1000)
},
appendCommssion: function(a) {
let info = a, obj = {}, coupon = '', coupon_link = '';
if (typeof a === 'object') {
obj = {
comm: a.wlCommission,
ratio: a.wlCommissionRatio,
plus_comm: parseFloat((a.plusCommissionShare * a.finalPrice / 100).toFixed(2)),
plus_ratio: a.plusCommissionShare
};
coupon_link = domain + '/jump/url?url=' + encodeURIComponent(this.itemUrl()) + '&coupon=' + encodeURIComponent(a.couponLink)
}
if (this.isMobile() == false) {
if (Object.keys(obj).length > 0) {
info = '<div class="general_comm" title="京东【普通会员】佣金:¥' + obj.comm + ',比例:' + obj.ratio + '%">普通会员:¥<b>' + obj.comm + '</b>(' + obj.ratio + '%)</div>' + '<div class="plus_comm" title="京东【PLUS会员】佣金:¥' + obj.plus_comm + ',比例:' + obj.plus_ratio + '%">PLUS会员:¥<b>' + obj.plus_comm + '</b>(' + obj.plus_ratio + '%) </div>';
if (a.hasCoupon == 1 && a.couponLink) {
coupon = '<div class="jt_pc_coupon"><a href="' + coupon_link + '" target="_blank" class="jt_cp_price" title="京淘助手出品!点击领取【满' + a.couponQuota + '减' + a.couponDiscount + '元】,剩余:' + a.couponRemainCnt + ' 张">¥<b>' + a.couponDiscount + '</b>联盟券</a></div>'
}
}
setTimeout(function() {
$(".J-summary-price").eq(0).after('<div class="jt_jd_pc_comm" title="京东佣金信息,京淘助手出品,仅供参考!"><div class="dt">佣金比例</div><div class="dd jd_comm">' + info + '</div>' + coupon + '</div>')
}, 1500)
} else {}
},
appendWqsPrice: function(a) {
let pcPrice = this.price;
if (this.isMobile() == false) {
$(".J-summary-price").eq(0).after('<div class="jt_jd_pc_price">' + '<div class="dt">微 Q 价</div><div class="dd">' + '<span class="jt_p_price" title="京淘助手出品,提供微信端、手Q端价格查询,仅供参考!"><span>¥</span>' + '<span class="jt_price">' + a + '</span>' + '<span class="jt_discount">(便宜:<b>' + (pcPrice - a).toFixed(2) + '</b>元)</span>' + '</span></div></div>')
} else {}
},
appendCompanyPrice: function(a) {
let pcPrice = this.price;
if (this.isMobile() == false) {
$(".J-summary-price").eq(0).after('<div class="jt_jd_pc_price" title="疑似京东企业账号下单价格">' + '<div class="dt">企 业 价</div><div class="dd">' + '<span class="jt_p_price" title="京淘助手出品,提供企业价格查询,仅供参考!"><span>¥</span>' + '<span class="jt_price">' + a + '</span>' + '<span class="jt_discount">(便宜:<b>' + (pcPrice - a).toFixed(2) + '</b>元)</span>' + '</span></div></div>')
} else {}
},
appendStock: function(a) {
if (this.isMobile() == false) {
let msg = "";
if (typeof a === 'number' && !isNaN(a)) {
msg = '<div class="jt_pc_stock" title="京淘助手提醒您,当前仅剩' + a + '件了,有需要抓紧下手吧!">仅剩:<b>' + a + '</b>件</div>'
} else {
msg = '<div class="jt_pc_stock jt_stock_more" title="京淘助手提醒您,当前库存5件以上!">库存:<b>' + a + '</b>件</div>'
}
if(msg){
$("#store-prompt").after(msg);
}
} else {}
},
getCommssion: function() {
GM_xmlhttpRequest({
method: "post",
headers: {
"content-type": "application/json;charset=UTF-8"
},
url: this.apiUrl.commssionUrl,
data: JSON.stringify({
page: 1,
data: {
key: this.skuid()
}
}),
onload: resp => {
if (resp.readyState == 4 && resp.status == 200) {
var a = JSON.parse(resp.responseText);
if (a) {
let info = "";
if (a.code == 200 && a.data.unionGoods && a.data.cache == false) {
info = a.data.unionGoods[0][0]
} else if (a.code == 80001) {
info = '未登录京东,请先登录!'
} else {
info = '暂无佣金信息!'
}
if(info){
this.appendCommssion(info);
}
} else {
console.log("服务器错误!")
}
}
}
})
},
getJdPcPrice: function() {
let jdu = this.getCookie("__jdu"), pin = this.getCookie('pin'), area = this.getArea();
let param = 'skuIds=J_' + this.skuid() + '&area=' + area + '&pduid=' + jdu + '&pdpin=' + pin + '&pin=' + pin + '&type=1&ext=11100000&source=item-pc';
GM_xmlhttpRequest({
method: "get",
url: this.apiUrl.pcPriceUrl + "?" + param,
onload: resp => {
if (resp.readyState == 4 && resp.status == 200) {
let pc = JSON.parse(resp.responseText);
if (pc && pc.length > 0) {
this.price = parseFloat(pc[0].p)
}
}
}
})
},
getWqsPrice: function() {
let jdu = this.getCookie("__jdu"), pin = this.getCookie('pin'), area = this.getArea();
let wqs_param = 'skuids=' + this.skuid() + '&origin=5&pdbp=0&pduid=' + jdu + '&area=' + area + '&pdpin=' + pin + '&pin=' + pin;
GM_xmlhttpRequest({
method: "get",
url: this.apiUrl.wqsPriceUrl + "?" + wqs_param,
onload: resp => {
if (resp.readyState == 4 && resp.status == 200) {
let data = JSON.parse(resp.responseText);
if (data && data.length > 0) {
let wqsPrice = data[0].p;
if (parseFloat(wqsPrice) < this.price) {
this.appendWqsPrice(wqsPrice)
}
}
}
}
})
},
getCompanyPrice: function() {
GM_xmlhttpRequest({
method: "get",
url: this.apiUrl.pcPriceUrl + "?ext=000000001&pin=zyqyg&skuids=J_" + this.skuid(),
onload: resp => {
if (resp.readyState == 4 && resp.status == 200) {
let data = JSON.parse(resp.responseText);
if (data && data.length > 0) {
let qy = data[0];
if (qy.epp != undefined && qy.epp) {
if (qy.up != undefined && qy.up == 'epp') {
this.appendCompanyPrice(qy.epp)
}
}
}
}
}
})
},
getRealStock: function() {
let id = this.skuid(), area = this.getArea(), fts_area = area.replace(/\_/g, ',');
GM_xmlhttpRequest({
method: "get",
headers: {
"content-type": "application/json;charset=UTF-8",
"referer": "https://cart.jd.com/cart.action"
},
url: this.apiUrl.stockUrl + "?ch=1&skuNum=" + this.skuid() + ",1;&area=" + fts_area + "&callback=",
onload: resp => {
if (resp.readyState == 4 && resp.status == 200) {
if (resp.responseText != undefined && resp.responseText.indexOf("html") < 0) {
let text = resp.responseText.replace(/\(/g, "").replace(/\)/g, "");
let json = JSON.parse(text);
if (json) {
let stock = json[id].c == '-1' ? '5+' : parseInt(json[id].c);
let status = parseInt(json[id].a);
if (stock && status != 34) {
this.appendStock(stock)
}
}
} else {
console.log('查询京东库存失败!')
}
}
}
})
},
apiUrl: {
domainApi: domain + "/api/plugin/monkey",
commssionUrl: "https://union.jd.com/api/goods/search",
pcPriceUrl: "https://p.3.cn/prices/mgets",
wqsPriceUrl: "https://pe.3.cn/prices/mgets",
stockUrl: "https://fts.jd.com/areaStockState/mget",
},
reader: function() {
GM_xmlhttpRequest({
method: "post",
url: this.apiUrl.domainApi,
data: JSON.stringify({
key: 'jd',
version: gm_info.version
}),
onload: resp => {
if (resp.readyState == 4 && resp.status == 200 && resp.responseText != undefined) {
let res = JSON.parse(resp.responseText);
let data = res.data;
if (data.status == true) {
let cssUrl = domain + "/monkey/css/v1/static.css?v=" + data.csv;
GM_xmlhttpRequest({
method: "get",
url: cssUrl,
onload: resp => {
if (resp.readyState == 4 && resp.status == 200 && resp.responseText != undefined) {
this.appendCss(cssUrl)
}
}
});
if (this.compareVersion(gm_info.version, data.minVersion) < 0) {
console.log('此版本已下架了,请到官网下载最新版使用!下载地址:' + domain + '/plugin?from=monkey_jd')
} else {
this.init()
}
}
}
}
})
},
config: function() {
if (typeof pageConfig != "undefined") {
return pageConfig.product
} else if (typeof window._itemOnly != 'undefined') {
return window._itemOnly.item
} else {
return false
}
},
getArea: function() {
var a = this.getCookie("ipLoc-djd");
if (a) {
a = a.replace(/-/g, "_").split('.')[0]
}
return a ? a : 1
},
skuid: function() {
let url = this.itemUrl();
let id = '';
if (url.indexOf("wareId") > -1) {
id = url.match(/wareId=([0-9]+)/i)[1]
} else if (url.indexOf("sku") > -1) {
id = url.match(/sku=([0-9]+)/i)[1]
} else {
id = url.match(/([0-9]+).html/i)[1]
}
return id
},
itemUrl: function() {
let url = $("link[rel=canonical]").attr("href");
if (!url) {
url = window.location.href
} else {
if (url.indexOf("http") < 0) {
url = "https:" + url
}
}
return url
},
getCookie: function(a) {
let arr = document.cookie.match(new RegExp("(^| )" + a + "=([^;]*)(;|$)"));
if (arr != null) return unescape(arr[2]);
return false
},
compareVersion: function(c, d) {
let arr1 = c.split('.'), arr2 = d.split('.');
let length1 = arr1.length, length2 = arr2.length;
let minlength = Math.min(length1, length2);
let i = 0;
for (i; i < minlength; i++) {
let a = parseInt(arr1[i]);
let b = parseInt(arr2[i]);
if (a > b) {
return 1
} else if (a < b) {
return -1
}
}
if (length1 > length2) {
for (let j = i; j < length1; j++) {
if (parseInt(arr1[j]) != 0) {
return 1
}
}
return 0
} else if (length1 < length2) {
for (let j = i; j < length2; j++) {
if (parseInt(arr2[j]) != 0) {
return -1
}
}
return 0
}
return 0
},
isMobile: function() {
let userAgent = navigator.userAgent || "";
userAgent = userAgent.toUpperCase();
if (userAgent == "" || userAgent.indexOf("PAD") > -1) {
return false
}
if (/MOBILE/.test(userAgent) && /(MICROMESSENGER|QQ\/)/.test(userAgent)) {
return true
}
let mobilePhoneList = ["IOS", "IPHONE", "ANDROID", "WINDOWS PHONE"];
for (var i = 0, len = mobilePhoneList.length; i < len; i++) {
if (userAgent.indexOf(mobilePhoneList[i]) > -1) {
return true;
break
}
}
return false
},
appendCss: function(a) {
let obj = "";
if (a.indexOf(".js") > -1) {
obj = document.createElement('script');
obj.setAttribute("type", "text/javascript");
obj.setAttribute("charset", "utf-8");
obj.setAttribute("src", a)
} else {
obj = document.createElement("link");
obj.setAttribute("charset", "utf-8");
obj.setAttribute("type", "text/css");
obj.setAttribute("rel", "stylesheet");
obj.setAttribute("href", a)
}
if (obj != "") {
document.getElementsByTagName("head")[0].appendChild(obj)
}
}
};
let jt = function() {
jtzs.reader();
return jtzs
};
return new jt()
})();