// ==UserScript==
// @name 【智狐】淘宝、天猫、京东、唯品会隐藏优惠券查询,自动显示历史价格和比价,拒绝虚假价格,让您购买到最优惠的商品,网购省钱小助手
// @name:zh 【智狐】淘宝、天猫、京东、唯品会隐藏优惠券查询,自动显示历史价格和比价,拒绝虚假价格,让您购买到最优惠的商品,网购省钱小助手
// @name:zh-TW 【智狐】淘寶、天貓、京東、唯品會隱藏優惠券查詢,自动显示历史价格和比价,拒絕虛假價格,讓您購買到最優惠的商品,網購省錢小助手
// @namespace zhCoupon
// @version 1.8.5
// @description 无强制跳转,自动显示淘宝、天猫、京东、唯品会隐藏优惠券,包括双十一和618的价格,让你快速了解商品低价,同款商品各大平台快速自动比价,同时显示比价列表,直接点击即可跳转其他平台,历史价格与比价功能正在开发中...
// @description:zh 无强制跳转,自动显示淘宝、天猫、京东、唯品会隐藏优惠券,包括双十一和618的价格,让你快速了解商品低价,同款商品各大平台快速自动比价,同时显示比价列表,直接点击即可跳转其他平台,历史价格与比价功能正在开发中...
// @description:zh-TW 無強製跳轉,自動顯示淘寶、天貓、京東、唯品會隱藏優惠券,包括雙十一和618的價格,讓你快速了解商品低價,同款商品各大平臺快速自動比價,同時顯示比價列表,直接點擊即可跳轉其他平臺,歷史價格與比價功能正在開發中...
// @author zhihu
// @run-at none
// @license End-User License Agreement
// @match *://*.taobao.com/*
// @match *://*.tmall.com/*
// @match *://chaoshi.detail.tmall.com/*
// @match *://*.tmall.hk/*
// @match *://*.liangxinyao.com/*
// @match *://*.jd.com/*
// @match *://*.jd.hk/*
// @match *://*.yiyaojd.com/*
// @match *://*.vip.com/*
// @match *://*.vipglobal.hk/*
// @exclude *://login.taobao.com/*
// @exclude *://login.tmall.com/*
// @exclude *://uland.taobao.com/*
// @exclude *://pages.tmall.com/*
// @exclude *://wq.jd.com/*
// @icon data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==
// @grant GM_xmlhttpRequest
// @grant GM.xmlHttpRequest
// @grant GM_getValue
// @grant GM.getValue
// @grant GM_setValue
// @grant GM.setValue
// @antifeature referral-link 【此提示为GreasyFork代码规范要求含有查券功能的脚本必须添加,请知悉!】
// @connect api.zhihupe.com
// @grant unsafeWindow
// @downloadURL none
// ==/UserScript==
(function() {
'use strict';
//全局对象
const window = unsafeWindow||window;
const API_DOMAIN = 'https://api.zhihupe.com';
//const API_DOMAIN = 'http://127.0.0.1:7001';
//---------------------------公共方法开始---------------------------
const Utils = {
//兼容 Tampermonkey | Violentmonkey | Greasymonkey 4.0+
getValue:function(name, value) {
if (typeof GM_getValue === "function") {
return GM_getValue(name, value);
} else {
return GM.getValue(name, value);
}
},
//兼容 Tampermonkey | Violentmonkey | Greasymonkey 4.0+
setValue:function(name, value) {
if (typeof GM_setValue === "function") {
GM_setValue(name, value);
} else {
GM.setValue(name, value);
}
},
/**
* 添加css
* @params {String||Array} css - css样式
*/
appendStyle(css){
let style = document.createElement('style');
if(css instanceof Array){
style.textContent = css.join('');
}else{
style.textContent = css
}
style.type = 'text/css';
let doc = document.head || document.documentElement;
doc.appendChild(style);
},
/**
* 添加js文件
* @params {String} url - js文件地址
*/
appendScript:function(type,content) {
let script = document.createElement('script');
if(type === 'url'){
script.src = content;
}else{
script.innerHTML = content;
}
var docu = document.body;
docu.appendChild(script);
},
getObjectValue(object,path,defValue){
let obj = object;
if(typeof path === 'string'){
const reg = /[^\[\].]+/g;
path = path.match(reg);
}
for(const key of path){
if(!obj) {
return defValue
}
obj = obj[key];
}
return obj === undefined ? defValue : obj;
},
getQueryParam(query,url = ''){
let search = ''
if(url&&url.indexOf('?' !== -1)){
search = url.split('?').slice(1).join();
}else{
search = window.location.search.replace('?','')
}
const queryArr = search.split('&');
let param = null;
queryArr.forEach(item => {
const paramArr = item.split('=');
if(paramArr[0] === query){
param = paramArr[1];
}
});
return param;
},
getUrlid(url) {
var id ="";
if (url.indexOf("?") != -1) {
url = url.split("?")[0]
}
if (url.indexOf("#") != -1) {
url = url.split("#")[0]
}
var text = url.split("/");
id = text[text.length - 1];
id = id.replace(".html", "");
return id
},
monitorElement(attr){
let attrArr = [];
if(attr instanceof Array&&attr.length > 0){
attrArr = [...attr];
}else{
attrArr.push(attr)
}
let element = null;
return new Promise((resolve, reject) => {
attrArr.forEach(ele =>{
let timer = null,count = 0;
element = document.querySelector(ele);
timer = setInterval(()=>{
if(element){
clearInterval(timer);
resolve(element);
}
if(count > 50){
clearInterval(timer);
reject('未找到元素节点');
}
element = document.querySelector(ele);
count ++
},200)
})
})
}
}
const initData = {
wenku:{
codeInputElement:"#code",
loginCode:"123456",
},
coupon:{
shopGuideGroupText:'捡漏导购Q群',
shopGuideGroup:'188872170',
hasCouponBtnText:'领券购买',
noCouponBtnText:'直接购买',
noCommissionBtnText:'搜索同款优惠',
buyUrl:'http://tool.wezhicms.com/coupon/getscan.php',
tbShortUrlApi:'https://api.shop.xuelg.com/?id={ID}&m=shangpin',
tbShortUrlApiReqQuery: 'shorturl',
blackElement:['.coupon-wrap','#toolbar-qrcode'],
taobao:{
detailCouponMountElement:['.SecurityPrice--securityPrice--25lJx-X','.Price--root--1CrVGjc'],
searchGoodsCardElement:['.Content--content--sgSCZ12 .Card--doubleCardWrapper--L2XFE73','.Content--content--sgSCZ12 .Card--doubleCardWrapperMall--uPmo5Bz','.J_TItems .item .photo a']
},
tmall:{
detailCouponMountElement:['.SecurityPrice--securityPrice--25lJx-X','.Price--root--1CrVGjc']
},
tmallcs:{
searchGoodsCardElement:['.feeds-list .feeds-item a']
},
jd:{
detailCouponMountElement:'#J-summary-top',
searchGoodsCardElement:['.J-goods-list .gl-i-wrap .p-img a','.jSearchListArea .jItem .jPic a']
}
}
}
class Coupon{
//优惠券查询地址
couponApiUrl = '';
//优惠券展示节点
initElement = null;
get isHasCoupon(){
return this.couponInfo?.couponAmount > 0;
}
constructor(platform){
this.platform = platform;
//优惠券信息
let couponInfo = {};
Object.defineProperty(this,'couponInfo',{
set(value){
couponInfo = value;
//更新优惠券信息
this.updateCouponHtml();
},
get(){
return couponInfo;
}
})
}
/*
获取优惠券信息
return {Promise}
*/
getCouponInfo(){
if(!this.goodsId) throw new TypeError('商品ID获取失败');
if(!this.couponApiUrl) throw new TypeError('优惠券查询链接不存在');
return new Promise((resolve, reject) => {
fetch(this.couponApiUrl,{
method:'GET',
mode:'cors',
}).then(r=>r.json()).then(response=>{
if(response.code === 1){
resolve(response.data)
}else{
reject(new TypeError(response.message))
}
}).catch(err=>{
reject(err)
})
});
}
getTbShortUrl(id){
const api = initData.coupon.tbShortUrlApi.replace('{ID}',id)
return new Promise((resolve, reject) => {
fetch(api,{
method:'GET',
mode:'cors',
}).then(r=>r.json()).then(response=>{
resolve(Utils.getObjectValue(response,initData.coupon.tbShortUrlApiReqQuery));
}).catch(err=>{
reject(err)
})
});
}
/*
*插入优惠券节点
* params {ElementObject} 定位元素对象
* params {String} position 插入位置
*/
async appendCouponElement(element,position = "afterend"){
//插入css
this.css&&Utils.appendStyle(this.css)
//插入Html
this.initElement = this.loadingElement||null;
if(this.initElement)element.insertAdjacentElement(position,this.initElement);
}
async updateCouponHtml(){
if(this.initElement){
this.initElement.innerHTML = this.couponHtml
//添加关闭二维码事件
const qr = document.querySelectorAll('.closeQr');
if(qr.length > 0){
console.log(qr)
Array.from(qr).forEach(e=>{e.onclick = ()=> e.parentNode.style.display = 'none'})
}
}
}
async updateCouponErrorHtml(){
if(this.initElement)this.initElement.innerHTML = this.couponHtml
}
}
class DetailCoupon extends Coupon{
css = `
.zhihu-coupon:hover .zhihu-scan{
display:block!important;
}
`
get mobileAppText(){
let text = '手机淘宝';
switch (this.platform) {
case 'tmall':
case 'taobao':
text = '手机淘宝'
break;
case 'jd':
text = '手机京东或微信'
break;
}
return text;
}
get couponHtml(){
let couponHtml = '