// ==UserScript==
// @name 优惠购
// @namespace http://www.newday.me/
// @version 1.1.5
// @icon http://tb.newday.me/taobao/favicon.ico
// @author 哩呵
// @description 以最优惠的价格,把宝贝抱回家。插件主要功能有:[1]淘宝全站商品列表的优惠查询 [2]淘宝、京东内部优惠券自动获取 [3]主流商城的商品历史低价与价格变动信息 [4]查看和领取最新的淘宝商家优惠券
// @match *://*.taobao.com/*
// @match *://*.tmall.com/*
// @match *://*.tmall.hk/*
// @match *://*.liangxinyao.com/*
// @match *://*.yao.95095.com/*
// @match *://item.jd.com/*
// @match *://item.jd.hk/*
// @match *://goods.kaola.com/product/*
// @match *://you.163.com/item/*
// @match *://item.yhd.com/*
// @match *://product.suning.com/*
// @match *://www.amazon.cn/dp/*
// @match *://www.amazon.cn/gp/*
// @match *://product.dangdang.com/*
// @match *://item.gome.com.cn/*
// @match *://detail.vip.com/*
// @match *://tb.newday.me/*
// @connect taobao.com
// @connect tmall.com
// @connect newday.me
// @require https://cdn.staticfile.org/jquery/1.12.4/jquery.min.js
// @require https://cdn.staticfile.org/jquery.qrcode/1.0/jquery.qrcode.min.js
// @require https://cdn.staticfile.org/snap.svg/0.5.1/snap.svg-min.js
// @require https://cdn.staticfile.org/echarts/4.1.0/echarts.min.js
// @require https://cdn.staticfile.org/vue/2.6.6/vue.min.js
// @run-at document-end
// @grant unsafeWindow
// @grant GM_getValue
// @grant GM_setValue
// @grant GM_addStyle
// @grant GM_xmlhttpRequest
// ==/UserScript==
(function () {
'use strict';
var container = (function () {
var obj = {
_defines: {},
_modules: {}
};
obj.define = function (name, requires, callback) {
name = obj.processName(name);
obj._defines[name] = {
requires: requires,
callback: callback
};
};
obj.require = function (name, cache) {
if (typeof cache == "undefined") {
cache = true;
}
name = obj.processName(name);
if (cache && obj._modules.hasOwnProperty(name)) {
return obj._modules[name];
}
else if (obj._defines.hasOwnProperty(name)) {
var requires = obj._defines[name].requires;
var callback = obj._defines[name].callback;
var module = obj.use(requires, callback);
cache && obj.register(name, module);
return module;
}
};
obj.use = function (requires, callback) {
var module = {
exports: {}
};
var params = obj.buildParams(requires, module);
var result = callback.apply(this, params);
if (typeof result != "undefined") {
return result;
}
else {
return module.exports;
}
};
obj.register = function (name, module) {
name = obj.processName(name);
obj._modules[name] = module;
};
obj.buildParams = function (requires, module) {
var params = [];
requires.forEach(function (name) {
params.push(obj.require(name));
});
params.push(obj.require);
params.push(module.exports);
params.push(module);
return params;
};
obj.processName = function (name) {
return name.toLowerCase();
};
return obj;
})();
container.define("config", [], function () {
var obj = {
base: "http://api.newday.me",
url: location.href,
browser: {
firefox: "firefox",
edge: "edge",
baidu: "baidu",
liebao: "liebao",
uc: "uc",
qq: "qq",
sogou: "sogou",
opera: "opera",
maxthon: "maxthon",
ie2345: "2345",
se360: "360",
chrome: "chrome",
other: "other"
},
site: {
taobao: "taobao",
jd: "jd",
kaola: "kaola",
guomei: "guomei",
yanxuan: "yanxuan",
yhd: "yhd",
amazon: "amazon",
suning: "suning",
dangdang: "dangdang",
vip: "vip",
newday: "newday"
},
option: {
taobao_detail: "taobao",
taobao_search: "taobao_search",
jd_detail: "jd",
kaola_detail: "kaola",
yanxuan_detail: "yanxuan",
yhd_detail: "yhd",
amazon_detail: "amazon",
suning_detail: "suning",
dangdang_detail: "dangdang",
guomei_detail: "guomei",
vip_detail: "vip"
}
};
obj.getUrl = function () {
return obj.url;
};
obj.setUrl = function (url) {
obj.url = url;
};
return obj;
});
container.define("util", ["config"], function (config) {
var obj = {};
obj.matchBrowserType = function (userAgent) {
var browser;
userAgent = userAgent.toLowerCase();
if (userAgent.match(/firefox/) != null) {
browser = config.browser.firefox;
} else if (userAgent.match(/edge/) != null) {
browser = config.browser.edge;
} else if (userAgent.match(/bidubrowser/) != null) {
browser = config.browser.baidu;
} else if (userAgent.match(/lbbrowser/) != null) {
browser = config.browser.liebao;
} else if (userAgent.match(/ubrowser/) != null) {
browser = config.browser.uc;
} else if (userAgent.match(/qqbrowse/) != null) {
browser = config.browser.qq;
} else if (userAgent.match(/metasr/) != null) {
browser = config.browser.sogou;
} else if (userAgent.match(/opr/) != null) {
browser = config.browser.opera;
} else if (userAgent.match(/maxthon/) != null) {
browser = config.browser.maxthon;
} else if (userAgent.match(/2345explorer/) != null) {
browser = config.browser.ie2345;
} else if (userAgent.match(/chrome/) != null) {
if (obj.existMime("type", "application/vnd.chromium.remoting-viewer")) {
browser = config.browser.se360;
} else {
browser = config.browser.chrome;
}
}
else {
browser = config.browser.other;
}
return browser;
};
obj.existMime = function (option, value) {
if (typeof navigator != "undefined") {
var mimeTypes = navigator.mimeTypes;
for (var mt in mimeTypes) {
if (mimeTypes[mt][option] == value) {
return true;
}
}
}
return false;
};
obj.randString = function (length) {
var possible = "abcdefghijklmnopqrstuvwxyz0123456789";
var text = "";
for (var i = 0; i < length; i++) {
text += possible.charAt(Math.floor(Math.random() * possible.length));
}
return text;
};
return obj;
});
container.define("core", ["config", "util"], function (config, util) {
var obj = {
info: {
aid: "",
uid: "",
version: "",
latest: "",
browser: "",
update_url: "update",
home_url: "home"
},
option: [],
config: {},
router: {
home: "http://tb.newday.me/script/option",
update: "http://tb.newday.me/script/option",
script: "https://gf.qytechs.cn/zh-CN/scripts/378081-%E4%BC%98%E6%83%A0%E8%B4%AD"
}
};
obj.getInfo = function () {
return obj.info;
};
obj.getOption = function () {
return obj.option;
};
obj.getRouter = function () {
return obj.router;
};
obj.getVersion = function () {
return obj.info.version;
};
obj.getAid = function () {
return obj.info.aid;
};
obj.getUid = function () {
return obj.info.uid;
};
obj.getBrowser = function () {
return obj.info.browser;
};
obj.setOption = function (values) {
var option = {};
Object.values(config.option).forEach(function (value) {
if (values.indexOf(value) >= 0) {
option[value] = "yes";
} else {
option[value] = "no";
}
});
obj.setValue("optionJson", JSON.stringify(option));
};
obj.isOptionActive = function (name) {
return obj.option.indexOf(name) >= 0 ? true : false;
};
obj.ajax = function (option) {
var details = {
url: option.url,
responseType: option.dataType,
onload: function (result) {
option.success && option.success(result.response);
},
onerror: function (result) {
option.error && option.error(result.error);
}
};
// 提交数据
if (option.data) {
details.method = "POST";
if (option.data instanceof FormData) {
details.data = option.data;
}
else {
var formData = new FormData();
for (var i in option.data) {
formData.append(i, option.data[i]);
}
details.data = formData;
}
}
else {
details.method = "GET";
}
// 自定义头
if (option.headers) {
details.headers = option.headers;
}
// 超时
if (option.timeout) {
details.timeout = option.timeout;
}
GM_xmlhttpRequest(details);
};
obj.appendStyle = function () {
var styleText = "#tb-cool-area{border:1px solid #eee;margin:0 auto;position:relative;clear:both}#tb-cool-area .tb-cool-area-home{position:absolute;top:5px;right:10px;z-index:10000}#tb-cool-area .tb-cool-area-home a{color:#515858;font-size:10px;text-decoration:none}#tb-cool-area .tb-cool-area-home a.new-version{color:#ff0036}#tb-cool-area .tb-cool-area-benefit{width:240px;float:left}#tb-cool-area .tb-cool-area-benefit .tb-cool-quan-qrcode{text-align:center;min-height:150px;margin-top:40px}#tb-cool-area .tb-cool-area-benefit .tb-cool-quan-qrcode canvas,#tb-cool-area .tb-cool-area-benefit .tb-cool-quan-qrcode img{margin:0 auto}#tb-cool-area .tb-cool-area-benefit .tb-cool-quan-title{margin-top:20px;color:#000;font-size:14px;font-weight:700;text-align:center}#tb-cool-area .tb-cool-area-benefit .tb-cool-quan-title span{color:#ff0036;font-weight:700}#tb-cool-area .tb-cool-area-benefit .tb-cool-quan-action{margin-top:10px;text-align:center}#tb-cool-area .tb-cool-area-benefit .tb-cool-quan-action a{text-decoration:none}#tb-cool-area .tb-cool-area-benefit .tb-cool-quan-action .tb-cool-quan-button{min-width:120px;padding:0 8px;line-height:35px;color:#fff;background:#ff0036;font-size:13px;font-weight:700;letter-spacing:1.5px;margin:0 auto;text-align:center;border-radius:15px;display:inline-block;cursor:pointer}#tb-cool-area .tb-cool-area-benefit .tb-cool-quan-action .tb-cool-quan-button.quan-none{color:#000;background:#bec5c5}#tb-cool-area .tb-cool-area-history{height:300px;overflow:hidden;position:relative}#tb-cool-area .tb-cool-area-history #tb-cool-area-chart,#tb-cool-area .tb-cool-area-history .tb-cool-area-container{width:100%;height:100%}#tb-cool-area .tb-cool-area-history .tb-cool-history-tip{position:absolute;margin:0;top:50%;left:50%;letter-spacing:1px;font-size:15px;transform:translateX(-50%) translateY(-50%)}#tb-cool-area .tb-cool-area-table{margin-top:10px;position:relative;overflow:hidden}#tb-cool-area .tb-cool-quan-tip{position:absolute;margin:0;top:50%;left:50%;letter-spacing:1px;font-size:15px;opacity:0;transform:translateX(-50%) translateY(-50%)}#tb-cool-area .tb-cool-quan-tip a{color:#333;font-weight:400;text-decoration:none}#tb-cool-area .tb-cool-quan-tip a:hover{color:#ff0036}#tb-cool-area .tb-cool-area-table .tb-cool-quan-table{width:100%;font-size:14px;text-align:center}#tb-cool-area .tb-cool-area-table .tb-cool-quan-table tr td{padding:4px;color:#1c2323;border-top:1px solid #eee;border-left:1px solid #eee}#tb-cool-area .tb-cool-area-table .tb-cool-quan-table tr td span{color:#ff0036;font-weight:700}#tb-cool-area .tb-cool-area-table .tb-cool-quan-table tr td:first-child{border-left:none}#tb-cool-area .tb-cool-area-table .tb-cool-quan-table .tb-cool-quan-link{width:60px;line-height:24px;font-size:12px;background:#ff0036;text-decoration:none;display:inline-block}#tb-cool-area .tb-cool-area-table .tb-cool-quan-table .tb-cool-quan-link-enable{cursor:pointer;color:#fff}#tb-cool-area .tb-cool-area-table .tb-cool-quan-table .tb-cool-quan-link-disable{cursor:default;color:#000;background:#ccc}#tb-cool-area .tb-cool-quan-empty .tb-cool-quan-tip{opacity:1}#tb-cool-area .tb-cool-quan-empty .tb-cool-quan-table{filter:blur(3px);-webkit-filter:blur(3px);-moz-filter:blur(3px);-ms-filter:blur(3px)}.tb-cool-box-area{position:absolute;top:10px;left:5px;z-index:9999}.tb-cool-box-wait{cursor:pointer}.tb-cool-box-already{position:relative}.tb-cool-box-info{width:auto!important;height:auto!important;padding:6px 8px!important;font-size:12px;color:#fff!important;border-radius:15px;cursor:pointer;text-decoration:none!important}.tb-cool-box-info:hover{text-decoration:none!important}.tb-cool-box-info:visited{text-decoration:none!important}.tb-cool-box-info-default{background:#3186fd!important}.tb-cool-box-info-find{background:#ff0036!important}.tb-cool-box-info-empty{color:#000!important;background:#ccc!important}.tb-cool-box-info-translucent{opacity:.33}.mui-zebra-module .tb-cool-box-info{font-size:10px}.zebra-ziying-qianggou .tb-cool-box-area{right:10px;left:auto}.import-shangou-itemcell .tb-cool-box-area{right:10px;left:auto}.item_s_cpb .tb-cool-box-area{top:auto;bottom:10px}.j-mdv-chaoshi .m-floor .tb-cool-box-area a{width:auto;height:auto}.left-wider .proinfo-main{margin-bottom:40px}.detailHd .m-info{margin-bottom:20px}";
GM_addStyle(styleText);
};
obj.jumpCouponLink = function (jumpFunc) {
jumpFunc();
};
obj.getValue = function (name) {
return GM_getValue(name);
};
obj.setValue = function (name, value) {
GM_setValue(name, value);
};
obj.printLog = function (data) {
if (typeof console != "undefined") {
if (typeof console != "undefined") {
console.log(data);
}
}
};
obj.initOption = function () {
return new Promise(function (resolve) {
var optionObject;
var optionJson = obj.getValue("optionJson");
if (optionJson) {
optionObject = JSON.parse(optionJson);
}
else {
optionObject = {};
}
var option = [];
Object.values(config.option).forEach(function (value) {
if (!(optionObject.hasOwnProperty(value) && optionObject[value] == "no")) {
option.push(value);
}
});
obj.option = option;
resolve();
});
};
obj.initInfo = function () {
return new Promise(function (resolve) {
obj.info.aid = GM_info.script.uuid;
obj.info.version = GM_info.script.version;
obj.info.browser = util.matchBrowserType(navigator.userAgent);
obj.router.home = obj.router.home + "?browser=" + obj.info.browser;
obj.router.update = obj.router.update + "?browser=" + obj.info.browser;
var name = "_uid_";
var uid = obj.getValue(name);
if (uid) {
obj.info.uid = uid;
}
else {
obj.info.uid = util.randString(32);
obj.setValue(name, obj.info.uid);
}
resolve();
});
};
obj.init = function (callback) {
var promiseList = [
obj.initInfo(),
obj.initOption()
];
Promise.all(promiseList).then(function () {
callback && callback();
});
};
return obj;
});
container.define("api", ["config", "core", "snap"], function (config, core, snap) {
var obj = {};
obj.itemQuery = function (url, callback) {
core.ajax({
url: config.base + "/taobao/tool/query",
dataType: "json",
data: {
item_url: url,
uid: core.getUid(),
aid: core.getAid(),
version: core.getVersion(),
browser: core.getBrowser()
},
success: function (response) {
callback(response);
},
error: function (error) {
callback("");
}
});
};
obj.basicQuery = function (itemId, callback) {
core.ajax({
url: config.base + "/taobao/tool/basic",
dataType: "json",
data: {
item_id: itemId,
source: "taobao",
uid: core.getUid(),
aid: core.getAid(),
version: core.getVersion(),
browser: core.getBrowser()
},
success: function (response) {
callback(response);
},
error: function (error) {
callback("");
}
});
};
obj.trendQuery = function (url, callback) {
core.ajax({
url: config.base + "/taobao/tool/trend",
dataType: "json",
data: {
item_url: url,
item_point: obj.getStrPoint(url),
uid: core.getUid(),
aid: core.getAid(),
version: core.getVersion(),
browser: core.getBrowser()
},
success: function (response) {
callback(response);
},
error: function (error) {
callback("");
}
});
};
obj.couponQueryCart = function (itemId, shopId, callback) {
var url = "https://bar.tmall.com/cueAssetMsg.htm?sellerId=" + shopId + "&itemId=" + itemId + "&bizInfo=..pc&_input_charset=UTF-8&callback=jsonp";
core.ajax({
url: url,
dataType: "text",
headers: {
"referer": "https://www.tmall.com/"
},
success: function (response) {
callback(response);
},
error: function (error) {
callback("");
}
});
};
obj.couponQueryShop = function (itemId, shopId, callback) {
core.ajax({
url: "https://cart.taobao.com/json/GetPriceVolume.do?sellerId=" + shopId,
dataType: "json",
success: function (response) {
callback(response);
},
error: function (error) {
callback("");
}
});
};
obj.getStrPoint = function (str) {
if (str.length < 2) {
return "0:0";
}
var path = "";
var current, last = str[0].charCodeAt();
var sum = last;
for (var i = 1; i < str.length; i++) {
current = str[i].charCodeAt();
if (i == 1) {
path = path + "M";
} else {
path = path + " L";
}
path = path + current + " " + last;
last = current;
sum = sum + current;
}
path = path + " Z";
var index = sum % str.length;
var data = snap.path.getPointAtLength(path, str[index].charCodeAt());
return data.m.x + ":" + data.n.y;
};
return obj;
});
container.define("app_detail", ["config", "core", "api", "echarts", "$"], function (config, core, api, echarts, $) {
var obj = {
trendData: null
};
obj.getSite = function () {
return obj.matchSite(config.getUrl());
};
obj.getItemUrl = function () {
return obj.matchItemUrl(config.getUrl());
};
obj.run = function () {
var site = obj.getSite();
switch (site) {
case config.site.taobao:
core.isOptionActive(config.option.taobao_detail) && obj.initDetailTaoBao();
break;
case config.site.jd:
core.isOptionActive(config.option.jd_detail) && obj.initDetailJd();
break;
case config.site.kaola:
core.isOptionActive(config.option.kaola_detail) && obj.initDetailKaoLa();
break;
case config.site.yanxuan:
core.isOptionActive(config.option.yanxuan_detail) && obj.initDetailYanXuan();
break;
case config.site.yhd:
core.isOptionActive(config.option.yhd_detail) && obj.initDetailYhd();
break;
case config.site.suning:
core.isOptionActive(config.option.suning_detail) && obj.initDetailSuNing();
break;
case config.site.amazon:
core.isOptionActive(config.option.amazon_detail) && obj.initDetailAmazon();
break;
case config.site.dangdang:
core.isOptionActive(config.option.dangdang_detail) && obj.initDetailDangDang();
break;
case config.site.guomei:
core.isOptionActive(config.option.guomei_detail) && obj.initDetailGuoMei();
break;
case config.site.vip:
core.isOptionActive(config.option.vip_detail) && obj.initDetailVip();
break;
default:
return false;
}
return true;
};
obj.initDetailTaoBao = function () {
if ($('#detail').length || $(".ju-wrapper").length) {
var html = obj.getAppendHtml();
if ($("#J_DetailMeta").length) {
$("#J_DetailMeta").append(html);
} else {
$("#detail").append(html + "<br/>");
}
var onEmpty = function () {
obj.showText("打开淘宝扫一扫");
};
obj.initDetail(onEmpty);
} else {
setTimeout(function () {
obj.initDetailTaoBao();
}, 1000);
}
};
obj.initDetailJd = function () {
if ($(".product-intro").length) {
var html = obj.getAppendHtml();
$(".product-intro").append(html);
var onEmpty = function () {
obj.showText("打开京东扫一扫");
};
obj.initDetail(onEmpty);
} else {
setTimeout(function () {
obj.initDetailJd();
}, 1000);
}
};
obj.initDetailKaoLa = function () {
if ($("#j-producthead").length) {
var html = obj.getAppendHtml();
$("#j-producthead").after(html);
var onEmpty = function () {
obj.showText("打开考拉扫一扫");
};
obj.initDetail(onEmpty);
} else {
setTimeout(function () {
obj.initDetailKaoLa();
}, 1000);
}
};
obj.initDetailYanXuan = function () {
if ($(".detailHd").length) {
var html = obj.getAppendHtml();
$(".detailHd").append(html);
var onEmpty = function () {
obj.showText("打开严选扫一扫");
};
obj.initDetail(onEmpty);
} else {
setTimeout(function () {
obj.initDetailYanXuan();
}, 1000);
}
};
obj.initDetailYhd = function () {
if ($(".fm_detail_one").length) {
var html = obj.getAppendHtml();
$(".fm_detail_one").append(html);
var onEmpty = function () {
obj.showText("打开一号店扫一扫");
};
obj.initDetail(onEmpty);
} else {
setTimeout(function () {
obj.initDetailYhd();
}, 1000);
}
};
obj.initDetailSuNing = function () {
if ($(".proinfo-container").length) {
var html = obj.getAppendHtml();
$(".proinfo-container").append(html);
var onEmpty = function () {
obj.showText("打开苏宁扫一扫");
};
obj.initDetail(onEmpty);
} else {
setTimeout(function () {
obj.initDetailSuNing();
}, 1000);
}
};
obj.initDetailAmazon = function () {
if ($("#centerCol").length) {
var html = obj.getAppendHtml();
$("#centerCol").after(html);
var onEmpty = function () {
obj.showText("手机扫一扫");
};
obj.initDetail(onEmpty);
} else {
setTimeout(function () {
obj.initDetailAmazon();
}, 1000);
}
};
obj.initDetailDangDang = function () {
if ($(".product_main").length) {
var html = obj.getAppendHtml();
$(".product_main").append(html);
var onEmpty = function () {
obj.showText("打开当当扫一扫");
};
obj.initDetail(onEmpty);
} else {
setTimeout(function () {
obj.initDetailDangDang();
}, 1000);
}
};
obj.initDetailGuoMei = function () {
if ($(".gome-container").length) {
var html = obj.getAppendHtml();
$(".gome-container").append(html);
var onEmpty = function () {
obj.showText("打开国美扫一扫");
};
obj.initDetail(onEmpty);
} else {
setTimeout(function () {
obj.initDetailGuoMei();
}, 1000);
}
};
obj.initDetailVip = function () {
if ($(".FW-product").length) {
var html = obj.getAppendHtml();
$(".FW-product").append(html);
var onEmpty = function () {
obj.showText("打开唯品会扫一扫");
};
obj.initDetail(onEmpty);
} else {
setTimeout(function () {
obj.initDetailVip();
}, 1000);
}
};
obj.initDetail = function (onEmpty) {
// 版本信息
var info = core.getInfo();
obj.showVersion(core.getInfo(), core.getRouter());
// 注册(不可用)事件
var site = obj.getSite();
if (site == config.site.taobao) {
obj.initCouponEvent();
} else if (site == config.site.amazon) {
obj.initResizeEvent();
}
// 商品查询
api.itemQuery(config.getUrl(), function (response) {
if (response && response.code == 1) {
var data = response.data;
// 二维码
obj.showQrcode(data.item_url);
// 价格趋势
obj.showChart(data.good_url);
// 隐藏优惠券
if (data.coupon_money > 0) {
obj.showCoupon(data);
}
else {
onEmpty();
}
// 优惠券列表
if (obj.getSite() == config.site.taobao) {
obj.showCouponList(data.item_id, data.shop_id);
}
}
else {
var itemUrl = obj.getItemUrl();
// 二维码
obj.showQrcode(itemUrl);
// 二维码
obj.showChart(itemUrl);
// 无优惠券
onEmpty();
}
});
};
obj.initResizeEvent = function () {
$(window).resize(function () {
obj.createChart();
});
};
obj.initCouponEvent = function () {
$(document).on("click", ".tb-cool-quan-link-enable", function () {
obj.openCouponLink($(this).attr("data-coupon"), $(this).attr("data-shop"));
});
$(document).on("click", ".tb-cool-quan-button.quan-exist", function () {
var couponUrl = $(this).attr("data-url");
var jumpFunc = function () {
location.href = couponUrl;
};
core.jumpCouponLink(jumpFunc);
});
};
obj.openCouponLink = function (couponId, shopId) {
var couponLink = obj.buildCouponLink(couponId, shopId);
window.open(couponLink, "领取优惠券", "width=600,height=600,toolbar=no,menubar=no,scrollbars=auto,resizeable=no,location=no,status=no");
};
obj.showCoupon = function (data) {
var html = "<p>券后价 <span>" + data.item_price_buy.toFixed(2) + "</span> 元</p>";
$(".tb-cool-quan-title").html(html);
html = '<a class="tb-cool-quan-button quan-exist" data-url="' + data.item_url + '">领' + data.coupon_money + '元内部券</a>';
$(".tb-cool-quan-action").html(html);
};
obj.showQrcode = function (url) {
$('.tb-cool-quan-qrcode').qrcode({ width: 150, height: 150, text: url });
};
obj.showText = function (buttonText, infoText) {
var infoTextArr = ["移动端<span>快捷</span>购买", "查看移动端<span>优惠</span>信息"];
if (!infoText) {
var index = (new Date()).valueOf() % infoTextArr.length;
infoText = infoTextArr[index];
}
var infoHtml = "<p>" + infoText + "</p>";
$(".tb-cool-quan-title").html(infoHtml);
buttonText || (buttonText = "手机扫一扫");
var buttonHtml = '<a class="tb-cool-quan-button quan-none">' + buttonText + '</a>';
$(".tb-cool-quan-action").html(buttonHtml);
};
obj.showVersion = function (info, router) {
var version = info.version;
var latest = info.latest;
var updateUrl = router.update;
var homeUrl = router.home;
var html = "";
if (latest && latest > version) {
html = '<a class="new-version" title="当前版本:' + version + ' 新版本:' + latest + '" target="_blank" href="' + updateUrl + '">[有新版本]</a>';
} else {
html = '<a title="当前版本:' + version + '" target="_blank" href="' + homeUrl + '">[ ' + version + ' ]</a>';
}
$(".tb-cool-area-home").html(html);
};
obj.showChart = function (itemUrl) {
$(".tb-cool-history-tip").html("查询历史价格中...");
api.trendQuery(itemUrl, function (response) {
obj.trendData = obj.parseTrendResponse(response);
obj.showChartRefresh();
});
};
obj.showChartRefresh = function () {
obj.showChartData(obj.trendData);
};
obj.showChartData = function (trendData) {
if (trendData) {
var option = obj.buildChartOption(trendData);
$(".tb-cool-area-container").html('<div id="tb-cool-area-chart"></div>');
echarts.init(document.getElementById("tb-cool-area-chart")).setOption(option);
$(".tb-cool-history-tip").html("");
}
else {
$(".tb-cool-history-tip").html("暂无商品历史价格信息");
}
};
obj.showCouponList = function (itemId, shopId) {
api.couponQueryCart(itemId, shopId, function (content) {
var couponList = obj.parseCouponListCart(itemId, shopId, content, {});
if (couponList) {
api.couponQueryShop(itemId, shopId, function (response) {
couponList = obj.parseCouponListShop(itemId, shopId, response, couponList);
obj.showCouponListLoginYes(couponList);
});
}
else {
couponList = obj.parseCouponListPadding();
obj.showCouponListLoginNo(couponList);
}
});
};
obj.showCouponListLoginYes = function (couponList) {
obj.buildCouponListTable(couponList);
};
obj.showCouponListLoginNo = function (couponList) {
obj.buildCouponListTable(couponList);
var loginUrl = obj.buildLoginUrl();
$(".tb-cool-quan-tip").html('<a href="' + loginUrl + '">登录(不可用)后可以查看店铺优惠券哦</a>');
$(".tb-cool-area-table").addClass("tb-cool-quan-empty");
};
obj.buildCouponListTable = function (couponList) {
var list = Object.values(couponList);
var compare = function (a, b) {
if (a.coupon_money == b.coupon_money) {
if (a.coupon_money_start > b.coupon_money_start) {
return 1;
} else if (a.coupon_money_start == b.coupon_money_start) {
return 0;
} else {
return -1;
}
} else {
if (a.coupon_money > b.coupon_money) {
return 1;
} else if (a.coupon_money == b.coupon_money) {
return 0;
} else {
return -1;
}
}
};
list.sort(compare);
var html = "";
list.forEach(function (item) {
html += "<tr>";
html += "<td>满 " + item.coupon_money_start + " 减 <span>" + item.coupon_money + "</span> 元</td>";
var couponCommon;
if (item.coupon_common == 1) {
couponCommon = "限定商品";
} else if (item.coupon_common == 0) {
couponCommon = "<span>通用</span>";
} else {
couponCommon = "--";
}
html += "<td> " + couponCommon + "</td>";
html += "<td>" + item.coupon_start + " ~ <span>" + item.coupon_end + "</span></td>";
html += "<td>已领 <span>" + item.coupon_num + "</span> 张</td>";
if (item.coupon_receive) {
html += '<td><a class="tb-cool-quan-link tb-cool-quan-link-disable">已领取</a></td>';
} else {
html += '<td><a class="tb-cool-quan-link tb-cool-quan-link-enable" data-shop="' + item.shop_id + '" data-coupon="' + item.coupon_id + '">领 取</a></td>';
}
html += "</tr>";
});
$(".tb-cool-quan-table").html(html);
};
obj.buildLoginUrl = function () {
var itemUrl = obj.getItemUrl();
return "https://login.tmall.com/?redirectURL=" + escape(itemUrl);
};
obj.buildCouponLink = function (couponId, shopId) {
return "https://market.m.taobao.com/apps/aliyx/coupon/detail.html?wh_weex=true&activity_" + "id=" + couponId + "&seller_id=" + shopId;
};
obj.buildChartOption = function (trendData) {
var text = "历史低价:{red|¥" + parseFloat(trendData.stat.min).toFixed(2) + "} ( {red|" + trendData.stat.date + "} )";
return {
title: {
left: "center",
subtext: text,
subtextStyle: {
color: "#000",
rich: {
red: {
color: "red"
}
}
}
},
tooltip: {
trigger: "axis",
axisPointer: {
type: "cross"
},
formatter: function (params) {
params = params[0];
var year = params.name.getFullYear();
var month = params.name.getMonth() + 1;
var day = params.name.getDate();
if (month < 10) {
month = "0" + month;
}
if (day < 10) {
day = "0" + day;
}
return "日期:" + year + "-" + month + "-" + day + "<br/>价格:¥" + params.value[1].toFixed(2);
}
},
dataZoom: [
{
type: "inside",
start: 0,
end: 100
}
],
grid: {
left: 0,
right: 20,
top: 50,
bottom: 10,
containLabel: true
},
xAxis: {
type: "time"
},
yAxis: {
type: "value",
scale: true
},
series: [
{
type: "line",
step: "end",
data: trendData.data,
lineStyle: {
color: "#ed5700"
},
markPoint: {
data: [
{
type: "min",
name: "最小值",
itemStyle: {
color: "green"
}
}
]
}
}
]
};
};
obj.parseTrendResponse = function (response) {
if (response && response.code == 1 && response.data.list.length) {
var stat = response.data.stat;
var list = response.data.list;
var trendData = {
stat: {
min: stat.min,
date: stat.date
},
data: []
};
list.forEach(function (item) {
var time = new Date(item.time * 1000);
var title = [
time.getFullYear(),
time.getMonth() + 1,
time.getDate()
].join('-');
var price = Math.round(item.price);
trendData.data.push({
name: time,
value: [
title,
price
]
});
});
return trendData;
}
else {
return null;
}
};
obj.parseCouponListPadding = function () {
return [
{
shop_id: "",
coupon_receive: false,
coupon_num: 0,
coupon_id: "",
coupon_money: 10,
coupon_money_start: 20,
coupon_start: "2018-01-01",
coupon_end: "2018-12-12",
coupon_common: 0
},
{
shop_id: "",
coupon_receive: false,
coupon_num: 0,
coupon_id: "",
coupon_money: 20,
coupon_money_start: 40,
coupon_start: "2018-01-01",
coupon_end: "2018-12-12",
coupon_common: 1
},
{
shop_id: "",
coupon_receive: false,
coupon_num: 0,
coupon_id: "",
coupon_money: 40,
coupon_money_start: 80,
coupon_start: "2018-01-01",
coupon_end: "2018-12-12",
coupon_common: 0
}
];
};
obj.parseCouponListCart = function (itemId, shopId, content, couponList) {
var jsonStr = content.replace("window.jsonp && jsonp(", "").replace("})", "}");
var response = JSON.parse(jsonStr);
if (response && response.oci && response.oci.c) {
var list = response.oci.c;
list.forEach(function (item) {
var couponId = item.sid;
if (!couponList.hasOwnProperty(couponId)) {
couponList[couponId] = {
shop_id: shopId,
coupon_receive: false,
coupon_num: 0,
coupon_id: couponId,
coupon_money: item.d,
coupon_money_start: parseFloat(item.c),
coupon_start: item.s.split(" ")[0],
coupon_end: item.l.split(" ")[0],
coupon_common: item.i
};
}
});
return couponList;
}
else {
return null;
}
};
obj.parseCouponListShop = function (itemId, shopId, response, couponList) {
if (response && response.priceVolumes) {
response.priceVolumes.forEach(function (item) {
var couponId = item.id;
var receive = item.status == "received";
if (couponList.hasOwnProperty(couponId)) {
couponList[couponId].coupon_receive = receive;
couponList[couponId].coupon_num = item.receivedAmount;
}
else {
var couponMoneyStart = item.condition.replace("满", "").split("减")[0];
var couponStart = item.timeRange.split("-")[0];
var couponEnd = item.timeRange.split("-")[1];
couponList[couponId] = {
shop_id: shopId,
coupon_receive: receive,
coupon_num: item.receivedAmount,
coupon_id: couponId,
coupon_money: parseFloat(item.price).toFixed(2),
coupon_money_start: parseFloat(couponMoneyStart).toFixed(2),
coupon_start: couponStart,
coupon_end: couponEnd,
coupon_common: -1
};
}
});
}
return couponList;
};
obj.matchItemUrl = function (url) {
var site = obj.matchSite(url);
var param = obj.parseUrlParam(url);
if (site == config.site.taobao) {
if (param.id) {
return "https://item.taobao.com/item.htm?id=" + param.id;
} else {
return url;
}
}
if (site == config.site.yanxuan) {
if (param.id) {
return "http://you.163.com/item/detail?id=" + param.id;
} else {
return url;
}
}
// 去除参数和哈希
url = url.split("?")[0];
url = url.split("#")[0];
if (site == config.site.guomei) {
url = url.replace("https", "http");
return url;
}
if (site == config.site.vip) {
url = url.replace("https", "http");
url = url.replace("detail.vip.com", "www.vip.com");
return url;
}
return url;
};
obj.matchSite = function (url) {
// 淘宝
if (url.indexOf("//item.taobao.com/item.htm") > 0 || url.indexOf("//detail.tmall.com/item.htm") > 0 || url.indexOf("//chaoshi.detail.tmall.com/item.htm") > 0 || url.indexOf("//detail.tmall.hk/hk/item.htm") > 0 || url.indexOf("//detail.liangxinyao.com/item.htm") > 0 || url.indexOf("//detail.yao.95095.com/item.htm") > 0) {
return config.site.taobao;
}
// 京东
if (url.indexOf("item.jd.com") > 0 || url.indexOf("item.jd.hk") > 0) {
return config.site.jd;
}
// 考拉
if (url.indexOf("goods.kaola.com") > 0) {
return config.site.kaola;
}
// 严选
if (url.indexOf("you.163.com/item") > 0) {
return config.site.yanxuan;
}
// 一号店
if (url.indexOf("item.yhd.com") > 0) {
return config.site.yhd;
}
// 苏宁
if (url.indexOf("product.suning.com") > 0) {
return config.site.suning;
}
// 亚马逊
if (url.indexOf("www.amazon.cn/dp") > 0 || url.indexOf("www.amazon.cn/gp") > 0) {
return config.site.amazon;
}
// 当当
if (url.indexOf("product.dangdang.com") > 0) {
return config.site.dangdang;
}
// 国美
if (url.indexOf("item.gome.com.cn") > 0) {
return config.site.guomei;
}
// 唯品会
if (url.indexOf("detail.vip.com") > 0) {
return config.site.vip;
}
// 插件主页
if (url.indexOf("tb.newday.me") > 0) {
return config.site.newday;
}
return null;
};
obj.parseUrlParam = function (url) {
if (url.indexOf("?")) {
url = url.split("?")[1];
}
var reg = /([^=&\s]+)[=\s]*([^=&\s]*)/g;
var obj = {};
while (reg.exec(url)) {
obj[RegExp.$1] = RegExp.$2;
}
return obj;
};
obj.getAppendHtml = function () {
return '<div id="tb-cool-area"><div class="tb-cool-area-home"></div><div class="tb-cool-area-benefit"><div class="tb-cool-quan-qrcode"></div><div class="tb-cool-quan-title"></div><div class="tb-cool-quan-action"></div></div><div id="tb-cool-area-history" class="tb-cool-area-history"><div class="tb-cool-area-container"></div><p class="tb-cool-history-tip"></p></div><div class="tb-cool-area-table"><table class="tb-cool-quan-table"></table><p class="tb-cool-quan-tip"></p></div></div>';
};
return obj;
});
container.define("app_search_taobao", ["config"], function (config) {
var obj = {};
obj.matchSelectorList = function () {
var url = config.getUrl();
var selectorList = [];
if (url.indexOf("//s.taobao.com/search") > 0 || url.indexOf("//s.taobao.com/list") > 0) {
// 搜索
selectorList.push(".items .item");
}
else if (url.indexOf("//www.taobao.com/markets") > 0) {
// 活动
selectorList = obj.matchSelectorListMarkets();
}
else if (url.indexOf("//www.taobao.com") > 0) {
// 首页
selectorList.push(".tbh-hotsale .item");
}
else if (url.indexOf("//neiyi.taobao.com") > 0) {
// 内衣
selectorList.push(".item-list li");
}
else if (url.indexOf("//qiang.taobao.com") > 0) {
// 淘抢购
selectorList.push(".qg-limit-list .qg-item");
}
else if (url.indexOf("//ju.taobao.com") > 0) {
// 聚划算
selectorList.push(".ju-wrapper li");
}
else if (url.indexOf("//mei.taobao.com") > 0) {
// 美妆
selectorList.push(".item-list .item-box li");
selectorList.push(".n-mei-category .J_pannel li");
selectorList.push(".J_dynamic .float-box");
selectorList.push(".item-list .J_ItemHover");
selectorList.push(".ju-box li");
selectorList.push(".spu-item .spu-img");
}
else if (url.indexOf("//g.taobao.com") > 0) {
// 全球购
selectorList.push(".items .item");
}
else if (url.indexOf("//pei.taobao.com") > 0) {
// 配件
selectorList.push(".module-wrap .item-box");
}
else if (url.indexOf("//wujin.taobao.com") > 0) {
// 五金
selectorList.push(".module-wrap .item-show");
}
else {
// 店铺
selectorList.push("#J_ShopSearchResult .item");
}
return selectorList;
};
// 市场
obj.matchSelectorListMarkets = function () {
var url = config.getUrl();
var selectorList = [];
if (url.indexOf("//www.taobao.com/markets/nvzhuang/") > 0) {
// 女装
selectorList.push(".item-box li");
}
else if (url.indexOf("//www.taobao.com/markets/nanzhuang/") > 0) {
// 男装
selectorList.push(".module-wrap .shop_list");
}
else if (url.indexOf("//www.taobao.com/markets/xie/") > 0) {
// 鞋靴
selectorList.push(".item-box li");
}
else if (url.indexOf("//www.taobao.com/markets/xiangbao/") > 0) {
// 箱包
selectorList.push(".item-box li");
}
else if (url.indexOf("//www.taobao.com/markets/qbb/") > 0) {
// 亲宝贝
selectorList.push(".brand-items .brand-item");
}
else if (url.indexOf("//www.taobao.com/markets/3c/") > 0) {
// 电场
selectorList.push(".parttwo-ul li");
selectorList.push(".pro-ul li");
}
else if (url.indexOf("//www.taobao.com/markets/amusement/") > 0) {
// 乐器
selectorList.push(".item-wrap .arrival-item");
selectorList.push(".pz-list .pz-li");
}
else if (url.indexOf("//www.taobao.com/markets/acg/") > 0) {
// 动漫
selectorList.push(".item-pannel li");
}
else if (url.indexOf("//www.taobao.com/markets/bangong/") > 0) {
// 办公
selectorList.push(".module-wrap .qiang-item");
selectorList.push(".module-wrap .item-show");
}
else if (url.indexOf("//www.taobao.com/markets/dingzhi/") > 0) {
// 定制
selectorList.push(".item-wrap .arrival-item");
selectorList.push(".pz-list .pz-li");
}
else if (url.indexOf("//www.taobao.com/markets/wujin/") > 0) {
// 五金
selectorList.push(".module-wrap .item-show");
}
else if (url.indexOf("//www.taobao.com/markets/promotion/") > 0) {
// 家庭保障
selectorList.push(".module-wrap .item");
}
else {
selectorList.push(".module-wrap .item");
selectorList.push(".module-wrap .shop_list");
selectorList.push(".module-wrap .item-show");
selectorList.push(".item-box li");
selectorList.push(".item-wrap .arrival-item");
selectorList.push(".brand-items .brand-item");
}
return selectorList;
};
return obj;
});
container.define("app_search_tmall", ["config"], function (config) {
var obj = {};
obj.matchSelectorList = function () {
var url = config.getUrl();
var selectorList = [];
if (url.indexOf("//list.tmall.com/search_product.htm") > 0) {
// 搜索
selectorList.push(".product");
selectorList.push(".chaoshi-recommend-list .chaoshi-recommend-item");
}
else if (url.indexOf("//www.tmall.com/wow/") > 0) {
selectorList = obj.matchSelectorListWow();
}
else if (url.indexOf("//pages.tmall.com") > 0 || url.indexOf("//618.tmall.com") > 0 || url.indexOf("//1111.tmall.com") > 0) {
selectorList = obj.matchSelectorListPages();
}
else if (url.indexOf("//www.tmall.com") > 0) {
// 首页
selectorList.push(".middle-column-con .one-grid-price");
selectorList.push(".wonderful-line .wonderful-item");
}
else if (url.indexOf("//import.tmall.com") > 0) {
// 天猫国际
selectorList.push(".mui-zebra-module .item");
}
else if (url.indexOf("//chaoshi.tmall.com") > 0) {
// 天猫超市
selectorList.push(".list .j_ItemInfo");
}
else if (url.indexOf("//3c.tmall.com") > 0) {
// 天猫电器城
selectorList.push(".mui-zebra-module .item");
selectorList.push(".itemlist .itemlist-mod");
selectorList.push(".floor-recommand .item");
}
else if (url.indexOf("//miao.tmall.com") > 0) {
// 天猫鲜生
selectorList.push(".mui-zebra-module .j_ItemContainer li");
}
else if (url.indexOf("//yao.tmall.com") > 0) {
// 天猫医药馆
selectorList.push(".zebra-yao-indexItem li");
selectorList.push(".yao-qiangCon li");
}
else if (url.indexOf("//wt.tmall.com") > 0) {
// 天猫营业厅
selectorList.push(".J_ItemListWrap li");
}
else if (url.indexOf("//suning.tmall.com") > 0) {
// 苏宁易购
selectorList.push(".J_TModule .itemarea");
selectorList.push(".J_TModule .tb-module .jdb");
selectorList.push("#J_ShopSearchResult .item");
}
else if (url.indexOf("//good.tmall.com") > 0) {
// 天猫心选
selectorList.push(".J_TModule .item");
}
else if (url.indexOf("//zhineng.tmall.com") > 0) {
// 天猫精灵智能
selectorList.push(".mui-zebra-module .item");
}
else if (url.indexOf("//nvzhuang.tmall.com") > 0) {
// 天猫女装
selectorList.push(".mui-zebra-module .w-lev2-lit");
}
else if (url.indexOf("//nvxie.tmall.com") > 0) {
// 天猫女鞋
selectorList.push(".fushi-special-extra a");
}
else if (url.indexOf("//bag.tmall.com") > 0) {
// 天猫箱包
selectorList.push(".mui-zebra-module .good");
}
else if (url.indexOf("//watch.tmall.com") > 0) {
// 天猫腕表
selectorList.push(".mui-zebra-module .item");
selectorList.push(".mui-zebra-module li");
}
else if (url.indexOf("//dai.tmall.com") > 0) {
// 天猫珠宝饰品
selectorList.push(".mui-zebra-module .good");
}
else if (url.indexOf("//shouji.tmall.com") > 0) {
// 天猫手机
selectorList.push(".mui-zebra-module .mod-g");
}
else if (url.indexOf("//baby.tmall.com") > 0) {
// 天猫母婴
selectorList.push(".mui-zebra-module .fl-camps");
}
else if (url.indexOf("//food.tmall.com") > 0) {
// 天猫零食
selectorList.push(".mui-zebra-module .item_s_cpa");
selectorList.push(".mui-zebra-module .item_s_cpb");
}
else if (url.indexOf("//jia.tmall.com") > 0) {
// 天猫家装
selectorList.push(".item-panel .item");
}
else if (url.indexOf("//car.tmall.com") > 0) {
// 天猫汽车
selectorList.push(".mui-zebra-module .col");
}
else if (url.indexOf("//book.tmall.com") > 0) {
// 天猫图书
selectorList.push(".mui-zebra-module .product a");
}
else if (url.indexOf("//new3c.tmall.com") > 0) {
// 天猫新首发
selectorList.push(".xpkw-container .xpkw-item");
}
else if (url.indexOf("//ku.tmall.com") > 0) {
// 酷玩街
selectorList.push(".new-recommend-content .new-recommend-block");
selectorList.push(".all-goods .goods_block");
}
else if (url.indexOf("//fenqi.tmall.com") > 0) {
// 花呗分期
selectorList.push(".mui-zebra-module .mod-g");
}
else if (url.indexOf("//content.tmall.com") > 0) {
selectorList.push(".mui-zebra-module li");
selectorList.push(".mui-zebra-module .juitem");
}
else {
// 店铺
selectorList.push("#J_ShopSearchResult .item");
}
return selectorList;
};
obj.matchSelectorListWow = function () {
var url = config.getUrl();
var selectorList = [];
if (url.indexOf("//www.tmall.com/wow/chaoshi/") > 0) {
selectorList.push(".mui-chaoshi-item-column");
}
else if (url.indexOf("//www.tmall.com/wow/fushi/") > 0) {
selectorList.push(".mui-zebra-module li");
selectorList.push(".popular-list .popular-item");
}
else {
selectorList.push(".mui-zebra-module li");
selectorList.push(".mui-zebra-module .item");
selectorList.push(".popular-list .popular-item");
}
return selectorList;
};
obj.matchSelectorListPages = function () {
var url = config.getUrl();
var selectorList = [];
if (url.indexOf("//pages.tmall.com/wow/import") > 0) {
selectorList.push(".cell-square");
selectorList.push(".gwtg-col-item");
}
else if (url.indexOf("//pages.tmall.com/wow/chaoshi/") > 0) {
selectorList.push(".mui-chaoshi-item-column");
}
else {
selectorList.push(".mui-zebra-module li");
selectorList.push(".mui-zebra-module .item-link");
selectorList.push(".mui-zebra-module .hot-item");
selectorList.push(".zebra-recommand-item-container .wrapper");
}
return selectorList;
};
return obj;
});
container.define("app_search_tmall_hk", ["config"], function (config) {
var obj = {};
obj.matchSelectorList = function () {
var url = config.getUrl();
var selectorList = [];
if (url.indexOf("//list.tmall.hk/search_product.htm") > 0) {
selectorList.push("#J_ItemList .product");
}
else if (url.indexOf("//www.tmall.hk") > 0) {
selectorList.push(".item-panel .item");
selectorList.push(".mui-zebra-module .import-shangou-itemcell");
}
else {
selectorList.push("#J_ShopSearchResult .item");
}
return selectorList;
};
return obj;
});
container.define("app_search", ["config", "core", "api", "$"], function (config, core, api, $, require) {
var obj = {};
obj.run = function () {
if (core.isOptionActive(config.option.taobao_search)) {
var url = config.getUrl();
var selectorList = [];
if (url.indexOf("taobao.com") > 0) {
selectorList = require("app_search_taobao").matchSelectorList();
}
else if (url.indexOf("tmall.com") > 0) {
selectorList = require("app_search_tmall").matchSelectorList();
}
else if (url.indexOf("tmall.hk") > 0) {
selectorList = require("app_search_tmall_hk").matchSelectorList();
}
else if (url.indexOf("//maiyao.liangxinyao.com/shop") > 0 || url.indexOf("//maiyao.liangxinyao.com/category") > 0) {
selectorList.push("#J_ShopSearchResult .item");
}
else if (url.indexOf("//www.liangxinyao.com") > 0 || url.indexOf("//maiyao.liangxinyao.com") > 0) {
selectorList.push(".mui-zebra-module .item");
selectorList.push(".zebra-ziying-qianggou li");
}
else {
selectorList.push("#J_ShopSearchResult .item");
}
obj.initSearchHtml(selectorList, 3000);
obj.initSearchEvent();
obj.basicQuery();
}
};
obj.initSearchHtml = function (selectorList, timeout) {
if (selectorList && selectorList.length > 0) {
selectorList.forEach(function (selector) {
obj.initSearchItemSelector(selector);
});
setInterval(function () {
obj.initSearchHtml(selectorList, timeout);
}, timeout);
}
};
obj.initSearchItemSelector = function (selector) {
$(selector).each(function () {
obj.initSearchItem(this);
});
};
obj.initSearchItem = function (selector) {
var $this = $(selector);
if ($this.hasClass("tb-cool-box-already")) {
return;
} else {
$this.addClass("tb-cool-box-already")
}
var nid = $this.attr("data-id");
if (!obj.isVailidItemId(nid)) {
nid = $this.attr("data-itemid");
}
if (!obj.isVailidItemId(nid)) {
if ($this.attr("href")) {
nid = location.protocol + $this.attr("href");
} else {
var $a = $this.find("a");
if (!$a.length) {
return;
}
nid = $a.attr("data-nid");
if (!obj.isVailidItemId(nid)) {
if ($a.hasClass("j_ReceiveCoupon") && $a.length > 1) {
nid = location.protocol + $($a[1]).attr("href");
} else {
nid = location.protocol + $a.attr("href");
}
}
}
}
if (obj.isValidNid(nid)) {
obj.appenBasicQueryHtml($this, nid);
}
};
obj.appenBasicQueryHtml = function (selector, nid) {
selector.append('<div class="tb-cool-box-area tb-cool-box-wait" data-nid="' + nid + '"><a class="tb-cool-box-info tb-cool-box-info-default" title="点击查询">待查询</a></div>');
};
obj.initSearchEvent = function () {
$(document).on("click", ".tb-cool-box-area", function () {
var $this = $(this);
if ($this.hasClass("tb-cool-box-wait")) {
obj.basicQueryItem(this);
} else if ($this.hasClass("tb-cool-box-info-translucent")) {
$this.removeClass("tb-cool-box-info-translucent");
} else {
$this.addClass("tb-cool-box-info-translucent");
}
});
};
obj.basicQuery = function () {
var items = $(".tb-cool-box-wait");
if (items.length) {
obj.basicQueryItem(items[0]);
} else {
setTimeout(obj.basicQuery, 2000);
}
};
obj.basicQueryItem = function (selector) {
var $this = $(selector);
$this.removeClass("tb-cool-box-wait");
var nid = $this.attr("data-nid");
api.basicQuery(nid, function (response) {
setTimeout(obj.basicQuery, 400);
if (response && response.code == 1) {
var data = response.data;
if (data.coupon_money > 0) {
obj.showBasicQueryFind($this, data.item_id, data.item_price_buy, data.coupon_money);
} else {
obj.showBasicQueryEmpty($this);
}
} else {
obj.showBasicQueryEmpty($this);
}
});
};
obj.showBasicQueryFind = function (selector, itemId, itemPriceBuy, couponMoney) {
selector.html('<a target="_blank" class="tb-cool-box-info tb-cool-box-info-find" title="切换透明度">券后 ' + itemPriceBuy + '(减' + couponMoney + '元)</a>');
};
obj.showBasicQueryEmpty = function (selector) {
selector.addClass("tb-cool-box-info-translucent");
selector.html('<a href="javascript:void(0);" class="tb-cool-box-info tb-cool-box-info-empty" title="切换透明度">暂无优惠</a>');
};
obj.isVailidItemId = function (itemId) {
if (!itemId) {
return false;
}
var itemIdInt = parseInt(itemId);
if (itemIdInt == itemId && itemId > 10000) {
return true;
}
else {
return false;
}
};
obj.isValidNid = function (nid) {
if (!nid) {
return false;
}
else if (nid.indexOf('http') >= 0) {
if (obj.isDetailPageTaoBao(nid) || nid.indexOf("//detail.ju.taobao.com/home.htm") > 0) {
return true;
}
else {
return false;
}
}
else {
return true;
}
};
obj.isDetailPageTaoBao = function (url) {
if (url.indexOf("//item.taobao.com/item.htm") > 0 || url.indexOf("//detail.tmall.com/item.htm") > 0 || url.indexOf("//chaoshi.detail.tmall.com/item.htm") > 0 || url.indexOf("//detail.tmall.hk/hk/item.htm") > 0 || url.indexOf("//detail.liangxinyao.com/item.htm") > 0 || url.indexOf("//detail.yao.95095.com/item.htm") > 0) {
return true;
} else {
return false;
}
};
return obj;
});
container.define("app_option", ["config", "core", "$", "vue"], function (config, core, $, vue) {
var obj = {};
obj.run = function () {
var url = config.getUrl();
if (url.indexOf(".newday.") >= 0) {
if (obj.isOptionPage()) {
obj.initOptionPage();
}
else if (obj.isActPage()) {
obj.initActPage();
}
return true;
}
else {
return false;
}
};
obj.initOptionPage = function () {
new vue({
el: "#container",
data: {
router: core.getRouter(),
info: core.getInfo(),
option: core.getOption()
},
mounted: function () {
this.initCheckBox();
},
watch: {
option: function (value) {
core.setOption(value);
}
},
methods: {
initCheckBox: function () {
$("body").addClass("init-checkbox-wait");
}
}
});
};
obj.initActPage = function () {
$("#dev-addon-info").val(JSON.stringify(core.getInfo()));
};
obj.isOptionPage = function () {
if ($("meta[name='yhg::option']").length) {
return true;
}
else {
return false;
}
};
obj.isActPage = function () {
if ($("meta[name='yhg::act']").length) {
return true;
}
else {
return false;
}
};
return obj;
});
container.define("app", ["core", "$"], function (core, $, require) {
var obj = {};
obj.run = function () {
// 重复检测
if (obj.existMeta()) {
core.printLog("addon setup already");
}
else {
core.printLog("addon setup success");
// 添加meta
obj.appendMeta();
// 加载样式
core.appendStyle();
// 运行应用
obj.runApp();
}
};
obj.runApp = function () {
var appList = [
"app_detail",
"app_option",
"app_search"
];
for (var i in appList) {
if (require(appList[i]).run() == true) {
break;
}
}
};
obj.existMeta = function () {
if ($("[name='yhg::status']").length) {
return true;
}
else {
return false;
}
};
obj.appendMeta = function () {
$('<meta name="yhg::status" content="on">').appendTo($("head"));
};
return obj;
});
// 注册(不可用)模块
container.register("$", window.$);
container.register("snap", window.Snap);
container.register("echarts", window.echarts);
container.register("vue", window.Vue);
// 执行操作
container.use(["core", "app"], function (core, app) {
core.init(function () {
app.run();
});
});
})();