// ==UserScript== // @name 搜索引擎超级助手, ===大家都说好系列😈 // @name:zh 搜索引擎超级助手, ===大家都说好系列😈 // @name:zh-TW 搜索引擎超級助手, ===大家都說好系列😈 // @namespace coolhii_search_engines_2000x // @version 1.0.1 // @description 搜索引擎导航[支持百度、搜狗、360搜索、必应、谷歌],支持自定义网址,并且对主流搜索引擎搜索结果做了优化,百度:结果跳转直达目标网址,并且把目标网址给展示到页面上,方便辨别(必应,google都是这种做法);google:结果链接新标签页打开,这样方便查阅;其他搜索引擎少量优化,如有好的建议,请留言! // @description:zh 搜索引擎导航[支持百度、搜狗、360搜索、必应、谷歌],支持自定义网址,并且对主流搜索引擎搜索结果做了优化,百度:结果跳转直达目标网址,并且把目标网址给展示到页面上,方便辨别(必应,google都是这种做法);google:结果链接新标签页打开,这样方便查阅;其他搜索引擎少量优化,如有好的建议,请留言! // @description:zh-TW 搜索引擎導航[支援百度、搜狗、360搜索、必應、穀歌],支援自定義網址,並且對主流搜索引擎搜索結果做了優化,百度:結果跳轉直達目標網址,並且把目標網址給展示到頁面上,方便辨別(必應,google都是這種做法);google:結果連結新標籤頁開啟,這樣方便查閱;其他搜索引擎少量優化,如有好的建議,請留言! // @author coolhii,大家好我叫肉肉 // @icon data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAAAXNSR0IArs4c6QAAAcVJREFUWEfFl41txDAIhckGHaEDEKkbtDdJR2k7SbtJ73bwPq6wICIOGDtKmkinU34Ofzw/IDfBxcd08frQBYCIbwz6wd90fgeAB5/fU0p0PnyEAIj4CQCycGuBr5QSPTt0uACcNS0s2UtgyfzVuEfPDIGYAEbWtCgFNmU2nu+G8ACy0nEVjJUpqmjJDYhbjy82AFWgZfGGF/QzBParjHmLDLECaCxOQWsv1LFLxlWMUAUXIKVU7g1UAZViyRgRBXi55ilRA6x+yPstkkZq0n1RYTeAmK/s60D2S4mSChpclAwVqLI9DEBUCQF472oFesynY1vgTSMe7YENQPcWeO5FRN2UmkZUlbPbhHrwiKN1cwmHkeWl1o+sTrhkPNALdDfUvhlrRLwNbjvlspQpKINpGVLzPP/knN85466B5A0jnUVzEgr0NE3fOefnSu5xBSSANWLVkKGer9+S3DkxVAW1WXZ0QstvzXnQ80pG2dGn9VpG2/QEAC+O412IEMBRhS4XE+qXDjUFu5UYBohGYgCxqYzDAaqZYvGuIM4CaHZPXRmnABgNbaXEvwA0IM7fAp0u9xK6RC38Uf97Om0LomqR+5cD/AF3eCgwUmpgqQAAAABJRU5ErkJggg== // @include *://www.baidu.com/* // @include *://www.so.com/s* // @include *://www.sogou.com/web* // @include *://www.sogou.com/sogou* // @include *://cn.bing.com/search* // @include *://www.bing.com/search* // @include *://www4.bing.com/search* // @include *://so.toutiao.com/search* // @include *://www.google.com/search* // @include *://www.google.com.hk/search* // @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/* // @exclude *://login.taobao.com/* // @exclude *://uland.taobao.com/* // @exclude *://pages.tmall.com/* // @require https://lf26-cdn-tos.bytecdntp.com/cdn/expire-1-M/jquery/3.2.1/jquery.min.js // @require https://lf9-cdn-tos.bytecdntp.com/cdn/expire-1-M/jquery.qrcode/1.0/jquery.qrcode.min.js // @connect tt.shuqiandiqiu.com // @connect j.jiayoushichang.com // @grant unsafeWindow // @grant GM_openInTab // @grant GM.openInTab // @grant GM_getValue // @grant GM.getValue // @grant GM_setValue // @grant GM.setValue // @grant GM_xmlhttpRequest // @grant GM.xmlHttpRequest // @grant GM_registerMenuCommand // @license AGPL License // @charset UTF-8 // @run-at document-idle // ==/UserScript== (function () { 'use strict'; //共有方法,全局共享 function commonFunction(){ this.GMgetValue = function (name, value=null) { let storageValue = value; if (typeof GM_getValue === "function") { storageValue = GM_getValue(name, value); } else if(typeof GM.setValue === "function"){ storageValue = GM.getValue(name, value); }else{ var arr = window.localStorage.getItem(name); if(arr != null){ storageValue = arr } } return storageValue; }; this.GMsetValue = function(name, value){ if (typeof GM_setValue === "function") { GM_setValue(name, value); } else if(typeof GM.setValue === "function"){ GM.setValue(name, value); }else{ window.localStorage.setItem(name, value) } }; this.GMaddStyle = function(css){ var myStyle = document.createElement('style'); myStyle.textContent = css; var doc = document.head || document.documentElement; doc.appendChild(myStyle); }; this.GMopenInTab = function(url, options={"active":true, "insert":true, "setParent":true}){ if (typeof GM_openInTab === "function") { GM_openInTab(url, options); } else { GM.openInTab(url, options); } }; this.addScript = function(url){ var s = document.createElement('script'); s.setAttribute('src',url); document.body.appendChild(s); }; this.randomNumber = function(){ return Math.ceil(Math.random()*100000000); }; this.request = function(mothed, url, param){ //网络请求 return new Promise(function(resolve, reject){ GM_xmlhttpRequest({ url: url, method: mothed, data:param, onload: function(response) { var status = response.status; var playurl = ""; if(status==200||status=='200'){ var responseText = response.responseText; resolve({"result":"success", "data":responseText}); }else{ reject({"result":"error", "data":null}); } } }); }) }; this.addCommonHtmlCss = function(){ var cssText = ` @keyframes fadeIn { 0% {opacity: 0} 100% {opacity: 1} } @-webkit-keyframes fadeIn { 0% {opacity: 0} 100% {opacity: 1} } @-moz-keyframes fadeIn { 0% {opacity: 0} 100% {opacity: 1} } @-o-keyframes fadeIn { 0% {opacity: 0} 100% {opacity: 1} } @-ms-keyframes fadeIn { 0% {opacity: 0} 100% {opacity: 1} } @keyframes fadeOut { 0% {opacity: 1} 100% {opacity: 0} } @-webkit-keyframes fadeOut { 0% {opacity: 1} 100% {opacity: 0} } @-moz-keyframes fadeOut { 0% {opacity: 1} 100% {opacity: 0} } @-o-keyframes fadeOut { 0% {opacity: 1} 100% {opacity: 0} } @-ms-keyframes fadeOut { 0% {opacity: 1} 100% {opacity: 0} } .web-toast-kkli9{ position: fixed; background: rgba(0, 0, 0, 0.7); color: #fff; font-size: 14px; line-height: 1; padding:10px; border-radius: 3px; left: 50%; transform: translateX(-50%); -webkit-transform: translateX(-50%); -moz-transform: translateX(-50%); -o-transform: translateX(-50%); -ms-transform: translateX(-50%); z-index: 999999999999999999999999999; white-space: nowrap; } .fadeOut{ animation: fadeOut .5s; } .fadeIn{ animation:fadeIn .5s; } `; this.GMaddStyle(cssText); }; this.webToast = function(params) { //小提示框 var time = params.time; var background = params.background; var color = params.color; var position = params.position; //center-top, center-bottom var defaultMarginValue = 50; if(time == undefined || time == ''){ time = 1500; } var el = document.createElement("div"); el.setAttribute("class", "web-toast-kkli9"); el.innerHTML = params.message; //背景颜色 if(background!=undefined && background!=''){ el.style.backgroundColor=background; } //字体颜色 if(color!=undefined && color!=''){ el.style.color=color; } //显示位置 if(position==undefined || position==''){ position = "center-bottom"; } //设置显示位置,当前有种两种形式 if(position==="center-bottom"){ el.style.bottom = defaultMarginValue+"px"; }else{ el.style.top = defaultMarginValue+"px"; } el.style.zIndex=999999; document.body.appendChild(el); el.classList.add("fadeIn"); setTimeout(function () { el.classList.remove("fadeIn"); el.classList.add("fadeOut"); /*监听动画结束,移除提示信息元素*/ el.addEventListener("animationend", function () { document.body.removeChild(el); }); el.addEventListener("webkitAnimationEnd", function () { document.body.removeChild(el); }); }, time); }; this.queryUrlParamter = function(text, tag) { //查询GET请求url中的参数 if(text.indexOf("?")!=-1){ //选取?后面的字符串,兼容window.location.search,前面的?不能去掉 var textArray = text.split("?"); text = "?"+textArray[textArray.length-1]; } var t = new RegExp("(^|&)" + tag + "=([^&]*)(&|$)"); var a = text.substr(1).match(t); if (a != null){ return a[2]; } return ""; }; this.isPC = function(){ var userAgentInfo = navigator.userAgent; var Agents = ["Android", "iPhone","SymbianOS", "Windows Phone", "iPad", "iPod"]; var flag = true; for (var v = 0; v < Agents.length; v++) { if (userAgentInfo.indexOf(Agents[v]) > 0) { flag = false; break; } } return flag; }; this.getBilibiliBV=function(){ var pathname = window.location.pathname; var bv = pathname.replace("/video/","").replace("/",""); return bv; }; this.getSystemOS=function(){ var u = navigator.userAgent; if (!!u.match(/compatible/i) || u.match(/Windows/i)) { return 'windows'; } else if (!!u.match(/Macintosh/i) || u.match(/MacIntel/i)) { return 'macOS'; } else if (!!u.match(/iphone/i) || u.match(/Ipad/i)) { return 'ios'; } else if (!!u.match(/android/i)) { return 'android'; } else { return 'other'; } }; this.RPCDownloadFile = function(fileName, url, savePath="D:/", RPCURL="ws://localhost:16800/jsonrpc", RPCToken="") { const self = this; if(!savePath){ savePath = "D:/"; } if(!RPCURL){ RPCURL = "ws://localhost:16800/jsonrpc"; } let options = { //下载配置文件 "dir":savePath, "max-connection-per-server": "16", "header":["User-Agent:"+navigator.userAgent+"", "Cookie:"+document.cookie+"", "Referer:"+window.location.href+""] } if(!!fileName) { options.out = fileName; } let jsonRPC = { "jsonrpc": "2.0", "id": "huahuacat", "method": "aria2.addUri", "params": [[url], options], } if (!!RPCToken) { jsonRPC.params.unshift("token:" + RPCToken); // 必须要加在第一个 } return new Promise(function(resolve, reject) { var webSocket = new WebSocket(RPCURL); webSocket.onerror = function(event) { console.log("webSocket.onerror", event); reject("Aria2连接错误,请打开Aria2和检查RPC设置!"); } webSocket.onopen = function(){ webSocket.send(JSON.stringify(jsonRPC)); } webSocket.onmessage = function(event){ let result = JSON.parse(event.data); switch (result.method) { case "aria2.onDownloadStart": resolve("Aria2 开始下载【"+fileName+"】"); webSocket.close(); break; case "aria2.onDownloadComplete": break; default: break; } } }); }; this.getElementObject = function(selector, allowEmpty = true, delay=200){ return new Promise((resolve,reject) =>{ let totalDelay = 0; let elementInterval = setInterval(()=>{ if(totalDelay >= 3000){ //总共检查3s,如果还是没找到,则返回 reject(false); clearInterval(elementInterval); } let element = document.querySelector(selector); let result = allowEmpty ? !!element : (!!element && !!element.innerHTML); if(result){ clearInterval(elementInterval); resolve(element); }else{ totalDelay += delay; } }, delay); }); }; /** * @param {Object} time * @param {Object} format * 时间格式化 * DateFormat(new Date(dateCreated), "yyyy-MM-dd hh:mm:ss") */ this.DateFormat = function(time, format) { var o = { "M+": time.getMonth() + 1, //月份 "d+": time.getDate(), //日 "h+": time.getHours(), //小时 "m+": time.getMinutes(), //分 "s+": time.getSeconds(), //秒 "q+": Math.floor((time.getMonth() + 3) / 3), //季度 "S": time.getMilliseconds() //毫秒 }; if(/(y+)/.test(format)){ format = format.replace(RegExp.$1, (time.getFullYear() + "").substr(4 - RegExp.$1.length)); } for(var k in o){ if(new RegExp("(" + k + ")").test(format)){ format = format.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length))); } } return format; } } //全局弹窗对象 const popup = (function(){ class Popup { constructor() { this.mask = document.createElement('div') this.setStyle(this.mask, { "width": '100%', "height": '100%', "backgroundColor": 'rgba(0, 0, 0, .6)', "position": 'fixed', "left": "0px", "top": "0px", "bottom":"0px", "right":"0px", "z-index":"99999" }) // 创建中间显示内容的水平并垂直居中的div this.content = document.createElement('div') this.setStyle(this.content, { "max-width": '400px', "width":"100%", "max-height": '600px', "backgroundColor": '#fff', "boxShadow": '0 0 2px #999', "position": 'absolute', "left": '50%', "top": '50%', "transform": 'translate(-50%,-50%)', "borderRadius": '3px' }) // 将这个小div放在遮罩中 this.mask.appendChild(this.content) } middleBox(param) { // 先清空中间小div的内容 - 防止调用多次,出现混乱 this.content.innerHTML = '' let title = '默认标题内容'; // 检测参数类型 if({}.toString.call(param) === '[object String]') { title = param } else if({}.toString.call(param) === '[object Object]') { title = param.title } // 将遮罩放在body中显示 document.body.appendChild(this.mask) // 给中间的小div设置默认的排版 // 上面标题部分 this.title = document.createElement('div') // 设置样式 this.setStyle(this.title, { "width": '100%', "height": '40px', "lineHeight": '40px', "boxSizing": 'border-box', "background-color":"#FF4D40", "color": '#FFF', "text-align": 'center', "font-weight":"700", "font-size":"16px" }) // 设置默认标题内容 this.title.innerText = title // 将标题部分放在中间div中 this.content.appendChild(this.title) // 关闭按钮 this.closeBtn = document.createElement('div') // 设置内容 this.closeBtn.innerText = '×' // 设置样式 this.setStyle(this.closeBtn, { "textDecoration": 'none', "color": '#666', "position": 'absolute', "right": '10px', "top": '0px', "fontSize": '25px', "color": '#FFF', "display":"inline-block", "cursor":"pointer" }) // 将关闭按钮放在中间小div中 this.title.appendChild(this.closeBtn) this.closeBtn.onclick = () => this.close() } // 弹出提示框 dialog(param) { this.middleBox(param); this.dialogContent = document.createElement('div') this.setStyle(this.dialogContent,{ "padding":"15px", "max-height":"400px" }) this.dialogContent.innerHTML = param.content; this.content.appendChild(this.dialogContent) param.onContentReady(this); } close() { document.body.removeChild(this.mask) window.location.reload(); } setStyle(ele, styleObj) { // 设置样式的函数 for(let attr in styleObj){ ele.style[attr] = styleObj[attr] } } } let popup = null; return (function() { if(!popup) { popup = new Popup() } return popup; })() })(); //全局统一方法对象 const innerVersionNo = "100000001"; const commonFunctionObject = new commonFunction(); commonFunctionObject.addCommonHtmlCss(); //统一html、css元素添加 /** * 搜索引擎资源提醒 */ function searchEnginesNavigation(){ this.customNavigationkey = "custom-navigation-key-8898"; this.searchEnginesData=[ {"host":"www.baidu.com", "element":"#content_right","elementInput":"#kw"}, {"host":"www.so.com", "element":"#side","elementInput":"#keyword"}, {"host":"www.sogou.com", "element":"#right","elementInput":"#upquery"}, {"host":"cn.bing.com", "element":"#b_context","elementInput":"#sb_form_q"}, {"host":"www.bing.com", "element":"#b_context","elementInput":"#sb_form_q"}, {"host":"www4.bing.com", "element":"#b_context","elementInput":"#sb_form_q"}, {"host":"so.toutiao.com", "element":".s-side-list","elementInput":"input[type='search']"}, {"host":"www.google.com", "element":"#rhs","elementInput":"input[type='text']"}, {"host":"www.google.com.hk","element":"#rhs","elementInput":"input[type='text']"} ]; this.defaultNavigationData = [ {"name":"资源搜索","list":[ {"name":"百度百科", "url":"https://baike.baidu.com/item/@@"}, {"name":"知乎搜索", "url":"https://www.zhihu.com/search?type=content&q=@@"}, {"name":"B站搜索", "url":"https://search.bilibili.com/all?keyword=@@&from_source=webtop_search&spm_id_from=333.851"}, {"name":"财经雪球", "url":"https://xueqiu.com/k?q=@@"}, {"name":"抖音搜索", "url":"https://www.douyin.com/search/@@"}, {"name":"搜狗|公众号", "url":"https://weixin.sogou.com/weixin?type=2&query=@@"}, {"name":"豆瓣搜索", "url":"https://www.douban.com/search?q=@@"}, {"name":"维基百科", "url":"https://en.wikipedia.org/w/index.php?search=@@"}, {"name":"法律法规", "url":"https://www.pkulaw.com/law/chl?Keywords=@@"}, {"name":"icon搜索", "url":"https://www.iconfont.cn/search/index?searchType=icon&q=@@"}, {"name":"github", "url":"https://github.com/search?q=@@"}, {"name":"csdn", "url":"https://so.csdn.net/so/search?q=@@&t=&u="}, {"name":"stackoverflow", "url":"https://stackoverflow.com/"}, ]}, {"name":"搜索引擎","list":[ {"name":"百度", "url":"https://www.baidu.com/s?wd=@@"}, {"name":"必应", "url":"https://cn.bing.com/search?q=@@"}, {"name":"google", "url":"https://www.google.com/search?q=@@"}, {"name":"360搜索", "url":"https://www.so.com/s?ie=utf-8&fr=none&src=360sou_newhome&nlpv=basest&q=@@"}, {"name":"搜狗", "url":"https://www.sogou.com/web?query=@@"}, {"name":"头条搜索", "url":"https://so.toutiao.com/search?dvpf=pc&source=input&keyword=@@"}, {"name":"yandex", "url":"https://yandex.com/search/?text=@@"} ]} ]; this.getNavigationData = function(element, elementInput){ const self = this; let navigationData = self.defaultNavigationData; let finalNavigationData = null; try{ //自定义的数据 let customNavigationData = commonFunctionObject.GMgetValue(self.customNavigationkey, null); if(!!customNavigationData){ finalNavigationData = [].concat(customNavigationData); }else{ finalNavigationData = navigationData; } }catch(e){ finalNavigationData = navigationData; } self.createHtml(element, elementInput, finalNavigationData); }; this.createCss = function(elementNum){ var innnerCss = ` .ddfdfd`+elementNum+`dffssqa{ margin-top:15px; } .ddfdfd`+elementNum+`dffssqa:nth-last{ margin-top:0px; } .ddfdfd`+elementNum+`dffssqa>.title{ font-size:16px; color:#000; } .ddfdfd`+elementNum+`dffssqa>.content-list{ } .ddfdfd`+elementNum+`dffssqa>.content-list>a{ display:inline-block; border:1px solid #ece5e5; border-radius:4px; text-align:center; margin-right:10px; margin-top:6px; overflow: hidden; white-space: nowrap; text-overflow:ellipsis; padding:2px 5px; box-sizing:border-box; line-height:20px; font-size:14px!important; text-decoration: none; } .ddfdfd`+elementNum+`dffssqa>.content-list>a:hover{ text-decoration: underline; } `; if($("#plugin_css_style_dddsoo").length==0){ $("body").prepend(""); } }; this.showSetingDialog = function(){ const self = this; var customNavigationData = ""; const customNavigation = commonFunctionObject.GMgetValue(self.customNavigationkey, null); if(!!customNavigation){ customNavigationData = JSON.stringify(customNavigation, null, 4); } const content = `
注意事项如下:
1、请严格按照格式添加,否则不生效
2、数据为json格式,请确保json格式正确,必要时请到https://www.json.cn/校验
3、点击下面”示例“按钮,查看具体格式情况
4、链接中的搜索关键词请用”@@“代替,脚本会自动替换成当前搜索词。例如:https://www.baidu.com/s?wd=@@
5、大家可以自定义导航数据,但是必须要注意数据格式,发现出现错误,可点“初始化”
`; popup.dialog({ "title":"自定义添加导航", "content":content, "onContentReady":function($that){ var $navigationExample = $that.dialogContent.querySelector(".navigation-example"); var $navigationClear = $that.dialogContent.querySelector(".navigation-clear"); var $navigationSave = $that.dialogContent.querySelector(".navigation-save"); var $navigationInit = $that.dialogContent.querySelector(".navigation-init"); var $textarea = $that.dialogContent.querySelector(".navigation-textarea"); $navigationExample.addEventListener("click", function(){ $textarea.value = JSON.stringify(self.defaultNavigationData, null, 4); }); $navigationClear.addEventListener("click", function(){ $textarea.value = ""; }); $navigationInit.addEventListener("click", function(){ $textarea.value = ""; commonFunctionObject.GMsetValue(self.customNavigationkey, null); }); $navigationSave.addEventListener("click", function(){ var content = $textarea.value; if(!content){ commonFunctionObject.GMsetValue(self.customNavigationkey, null); commonFunctionObject.webToast({"message":"保存成功:数据为空", "background":"#FF4D40"}); return; } if(content.length==0 || content.indexOf("{")==-1 || content.indexOf("[")==-1){ commonFunctionObject.webToast({"message":"格式错误,请更正", "background":"#FF4D40"}); return; } try{ var contentJson = JSON.parse(content); if(Array.isArray(contentJson)){ //开始必须是数组 var isOK = true; for(var i=0; i"; html += "
"+navigationData[i].name+"
"; html += "
"; for(var j=0;j"+name+"" } html += "
"; html += ""; } // html += `
*该数据由油猴脚本提供    🔧自定义网址
`; html += ""; //添加css 添加html self.createCss(elementNum); $element.prepend(html); $("#dsdsd99mmmjj7760011 a[name='navigation']").on("click", function(e){ commonFunctionObject.GMopenInTab($(this).data("url").replace("@@",$(elementInput).val())); e.preventDefault() }); $("#dsdsd99mmmjj7760011 a[name='customNavigation']").on("click", function(e){ self.showSetingDialog(); e.preventDefault() }) } isComplate = true; } }, 100); }; this.hookBaidu = function(){ let items = document.querySelectorAll("#content_left>div"); for(let item of items){ //给处理完成的做一个标识 if(!!item.getAttribute("baidu_dealxx")){ continue; } item.setAttribute("baidu_dealxx","--"); let a = item.querySelector("a"); if(!a || !a.href){ continue; } //标注了html网址的忽略 let OP_LOG_LINK = item.querySelector(".OP_LOG_LINK"); if(!!OP_LOG_LINK && OP_LOG_LINK.innerText.search("http")!=-1){ continue; } //有多个点击点的忽略 let cGapBottomSmall = item.querySelector(".c-gap-bottom-small"); if(!!cGapBottomSmall){ continue; } //https://www.baidu.com/s?wd=一夜醒来欠地铁600多万?官方回应 if (a.href.includes("www.baidu.com/link?url=")) { let url = item.getAttribute("mu"); if (url && url != null && !url.includes("nourl.ubs.baidu.com")) { a.href = url; item.innerHTML += `
`+url+`
`; } } let itemNews = item.querySelectorAll("[class^=single-card-wrapper] div,[class^=group-wrapper] div"); if(!itemNews){ continue; } //single-card-wrapper: https://www.baidu.com/s?ie=UTF-8&wd=es6 xxx的最新相关信息 //group-wrapper: https://www.baidu.com/s?ie=UTF-8&wd=五一消费成绩单折射市场活力 资讯 for(let itemNew of itemNews){ let dataUrl = null; let divs = itemNew.querySelectorAll("div"); for (let div of divs) { if ((dataUrl = div.getAttribute("data-url"))) { let a = itemNew.querySelector("a"); a.setAttribute("href", dataUrl); } } } } }; this.hookGoogle = function(){ let items = document.querySelectorAll("#center_col a"); for(let a of items){ if(!a.getAttribute("target")) a.setAttribute("target","_blank"); } }; this.hooks = function(){ const host = window.location.host; const href = window.location.href; const self = this; setInterval(function(){ if(host==="www.baidu.com"){ self.hookBaidu(); }else if(host==="www.google.com" || host==="www.google.com.hk"){ self.hookGoogle(); } }, 300); }; this.show = function(){ const self = this; const host = window.location.host; const href = window.location.href; if((host==="www.baidu.com") || (host==="www.so.com" && href.indexOf("www.so.com/s")!=-1) || (host==="www.sogou.com" && (href.indexOf("www.sogou.com/web")!=-1 || href.indexOf("www.sogou.com/sogou")!=-1)) || (host==="cn.bing.com" && href.indexOf("cn.bing.com/search")!=-1) || (host==="www.bing.com" && href.indexOf("www.bing.com/search")!=-1) || (host==="www4.bing.com" && href.indexOf("www4.bing.com/search")!=-1) || (host==="so.toutiao.com" && href.indexOf("so.toutiao.com/search")!=-1) || (host==="www.google.com" && href.indexOf("www.google.com/search")!=-1) || (host==="www.google.com.hk" && href.indexOf("www.google.com.hk/search")!=-1)){ let currentSearchEnginesData = null; for(var i=0; i{ let totalDelay = 0; let elementInterval = setInterval(()=>{ if(totalDelay >= 3000){ //总共检查3s,如果还是没找到,则返回 reject(false); clearInterval(elementInterval); } let element = document.querySelector(selector); let result = allowEmpty ? !!element : (!!element && !!element.innerHTML); if(result){ clearInterval(elementInterval); resolve(element); }else{ totalDelay += delay; } }, delay); }); } } //优惠券相关功能 class Coupon{ platforms = ["detail.tmall.com", "item.taobao.com", "item.jd.com", "item.yiyaojd.com", "npcitem.jd.hk", "detail.tmall.hk"]; constructor(){ this.commonTools = new CommonTools(); } isRun(){ for(var i=0; i{ this.randomSpmValue(); }, 2000); } } async createCouponHtml(platform, goodsId, goodsName){ if(!platform || !goodsId) return; const goodsCouponUrl = "http://tt.shuqiandiqiu.com/api/coupon/discover?no=5&v=1.0.2&pl="+platform+"&id="+goodsId+"&qu="+goodsName; const goodsPrivateUrl = "http://tt.shuqiandiqiu.com/api/private/change/coupon?no=5&v=1.0.2&platform="+platform+"&id="; try{ const data = await this.commonTools.request("GET", goodsCouponUrl, null); if(data.code=="success" && !!data.result){ const result = JSON.parse(data.result).data; if(!result || result==="null" || !result.css || !result.html || !result.handler){ return; } const cssText = result.css, htmlText = result.html, handler = result.handler, templateId = result.templateId; if(!cssText || !htmlText || !handler){ return; } $("body").prepend(""); // 添加HTML const handlers = handler.split("@"); for(var i=0; i{ event.stopPropagation(); event.preventDefault(); let couponId = $template.data("id"); if(!!couponId){ this.commonTools.request("GET", goodsPrivateUrl+couponId, null).then((resutData2)=>{ if(resutData2.code==="success" && !!resutData2.result){ let url = JSON.parse(resutData2.result).url; if(!!url) GM_openInTab(url, {active:true}); } }); } }); setInterval(()=>{ $template.find("*").each(function(){ $(this).removeAttr("data-spm-anchor-id"); }); },400); //canvas画二维码 var $canvasElement = $("#ca"+templateId); if($canvasElement.length == 0){ return; } let couponId = $template.data("id"); this.commonTools.request("GET", goodsPrivateUrl+couponId, null).then((resutData2)=>{ if(resutData2.code==="success" && !!resutData2.result){ let img = JSON.parse(resutData2.result).img; if(!!img){ var canvasElement = document.getElementById("ca"+templateId); var cxt = canvasElement.getContext("2d"); var imgData = new Image(); imgData.src = img; imgData.onload=function(){ cxt.drawImage(imgData, 0, 0, imgData.width, imgData.height); } } } }); } }catch(e){} } showGoodsQRcode(platform){ if(platform==="jd"){ //京东不需要这个方法 return; } const elementId = Math.ceil(Math.random()*100000000)+"qrcode"; const width = 130; const title = platform=="jd" ? "京东APP扫码查看此商品":"淘宝APP扫码查看此商品"; const text = platform=="jd" ? window.location.href : window.location.href.split("?")[0] + "?id="+this.commonTools.getParamterQueryUrl(window.location.search, "id"); var html = `
`+title+`
`; $("body").append(html); jQuery('#'+elementId).qrcode({ render: "canvas", width: width, height: width, foreground: "#000", background: "#FFF", text: text }); console.log("text", text); }; comparePrice(){ //比价开发中..... } async start(){ if(this.isRun()){ this.runAliDeceptionSpm(); const platform = this.commonTools.getPlatform(); if(!!platform){ this.showGoodsQRcode(platform); const goodsData = await this.getGoodsData(platform); this.createCouponHtml(platform, goodsData.goodsId, goodsData.goodsName); } if(platform=="tmall"){ //tmall如果sku太多就折叠 const skuItemWrapper = await this.commonTools.getElementAsync("[class='skuItemWrapper']", false); if(skuItemWrapper != null){ const { style } = skuItemWrapper; style.maxHeight = "400px"; style.overflow = "auto"; } } } } } class SearchPageObject{ intervalIsRunComplete = true; //定时任务一个循环是否完成 constructor(){ this.commonTools = new CommonTools(); } pickupSearchElements(){ //收集列表的元素 const selectorElementList = new Array(); const url = window.location.href; if(url.indexOf("://s.taobao.com/search")!=-1 || url.indexOf("://s.taobao.com/list")!=-1) { //淘宝搜索页面 selectorElementList.push({"element":".items >.item", "page":"taobao"}); selectorElementList.push({"element":".Content--content--sgSCZ12 .Card--doubleCardWrapper--L2XFE73", "page":"taobao_new"}); selectorElementList.push({"element":".Content--content--sgSCZ12 .Card--listCardWrapper--ax09OfT", "page":"taobao_new"}); selectorElementList.push({"element":".Content--content--sgSCZ12 .Card--doubleCardWrapperMall--uPmo5Bz", "page":"taobao_new"}); selectorElementList.push({"element":".Content--content--sgSCZ12 .Card--listCardWrapperMall--E3jI8L4", "page":"taobao_new"}); }else if(url.indexOf("taobao.com/category")!=-1){ //淘宝店铺分类 selectorElementList.push({"element":"dl.item", "page":"taobao_category"}); }else if(url.indexOf("taobao.com/search.htm")!=-1){ //淘宝店铺搜索 selectorElementList.push({"element":"dl.item", "page":"taobao_shop_search"}); } else if (url.indexOf("://list.tmall.com/search_product.htm")!=-1 || url.indexOf("://list.tmall.com//search_product.htm")!=-1 || url.indexOf("://list.tmall.com/coudan/search_product.htm")!=-1) { //天猫超市 selectorElementList.push({"element":".product", "page":"tmall_chaoshi_search"}); selectorElementList.push({"element":".chaoshi-recommend-list .chaoshi-recommend-item", "page":"tmall_chaoshi_search_new"}); //新天猫超市 }else if (url.indexOf("//list.tmall.hk/search_product")!=-1) { //天猫国际 selectorElementList.push({"element":"#J_ItemList .product", "page":"tmall_hk"}); }else if(url.indexOf("tmall.com/category-")!=-1){ //天猫分类 selectorElementList.push({"element":"#J_ShopSearchResult dl.item", "page":"tmall_category"}); }else if(url.indexOf("tmall.com/category-")!=-1){ //天猫旗舰店分类 selectorElementList.push({"element":"#J_ShopSearchResult dl.item", "page":"tmall_category"}); }else if(url.indexOf(".tmall.com/shop/view_shop.htm")!=-1){ //天猫旗舰全部展示 selectorElementList.push({"element":"dl.item", "page":"tmall_shop_01"}); }else if(url.indexOf(".tmall.com/search.htm")!=-1){ selectorElementList.push({"element":"dl.item", "page":"tmall_shop_search"}); } else if(url.indexOf("//maiyao.liangxinyao.com/shop/view_shop.htm")!=-1 || url.indexOf("//maiyao.liangxinyao.com/search.htm")!=-1 || url.indexOf("//maiyao.liangxinyao.com/category")!=-1){ //阿里大药房 selectorElementList.push({"element":"#J_ShopSearchResult dl.item", "page":"ali_yao"}); } else if (url.indexOf("//search.jd.com/Search")!=-1) { //京东搜索 selectorElementList.push({"element":"#J_goodsList li.gl-item", "page":"jd"}); }else if(url.indexOf("//search.jd.hk/Search")!=-1){ //京东国际 selectorElementList.push({"element":"#plist li.gl-item", "page":"jd_hk"}); }else if(url.indexOf("//mall.jd.com/view_search")!=-1){ //京东大药房 selectorElementList.push({"element":"li.jSubObject", "page":"jd_yao"}); } return selectorElementList; } createAllElementHtml(elementData){ //为所有的商品创建提示 const self = this; $(elementData.element).each(function(){ //遍历所有的商品框 self.createOneElementHtml($(this), elementData); }); self.intervalIsRunComplete = true; } /** * 为商品box添加有券提醒 * @param {Object} $element 每一个商品box * @param {Object} elementData id and page */ async createOneElementHtml($element, elementData){ //查询到每个商品list if($element.attr("completebox")){ //当存在时,说明已经处理过了 return; } $element.css("position","relative"); var page = elementData.page; var goodsDetailUrl = null; if(page==="taobao"){ goodsDetailUrl = $element.find("a[id^='J_Itemlist_TLink_']").attr("href"); }else if(page==="taobao_new"){ let href = $element.attr("href"); goodsDetailUrl = href.indexOf("http") == -1 ? (location.protocol + href) : href; }else if(page==="taobao_category"){ goodsDetailUrl = $element.find(".J_TGoldData").attr("href"); }else if(page==="taobao_shop_search"){ goodsDetailUrl = $element.find(".J_TGoldData").attr("href"); }else if(page==="ali_yao"){ goodsDetailUrl = $element.find(".J_TGoldData").attr("href"); }else if(page==="tmall_chaoshi_search"){ let href = $element.find("div.product-img").find("a").attr("href"); goodsDetailUrl = href.indexOf("http") ==-1 ? (location.protocol + href) : href; }else if(page==="tmall_chaoshi_search_new"){ let href = !!$element.attr("href")?$element.attr("href"):$element.find("a").attr("href"); goodsDetailUrl = href.indexOf("http") ==-1 ? (location.protocol + href) : href; }else if(page==="tmall_hk"){ goodsDetailUrl = $element.find("a.productImg").attr("href"); }else if(page==="tmall_category"){ goodsDetailUrl = $element.find(".J_TGoldData").attr("href"); }else if(page==="tmall_shop_01"){ goodsDetailUrl = $element.find("dt.photo").find("a").attr("href"); }else if(page==="tmall_shop_search"){ goodsDetailUrl = $element.find(".J_TGoldData").attr("href"); } else if(page==="jd"){ goodsDetailUrl = $element.find("div.p-img").find("a").attr("href"); }else if(page==="jd_hk"){ goodsDetailUrl = $element.find("div.p-img").find("a").attr("href"); }else if(page==="jd_yao"){ goodsDetailUrl = $element.find("div.jPic").find("a").attr("href"); } if(!goodsDetailUrl){ return; } // console.log(goodsDetailUrl); var analysisData = null; if(page==="jd" || page==="jd_hk"){ var jdId = this.commonTools.getEndHtmlIdByUrl(goodsDetailUrl); if(!!jdId) analysisData = {"id":jdId, "platform":"jd"}; }else{ var platform = this.commonTools.getPlatform(goodsDetailUrl); var id = this.commonTools.getParamterQueryUrl(goodsDetailUrl, "id"); if(platform && id){ analysisData = {"id":id, "platform":platform}; } } if(!analysisData){ return; } try{ const searchUrl = "http://j.jiayoushichang.com/api/ebusiness/coupon/exist/"+analysisData.platform+"?id="+analysisData.id; const data = await this.commonTools.request("GET", searchUrl, null); if(data.code=="success" && !!data.result){ const tip = JSON.parse(data.result).tip; if(tip){ $element.append(tip); } } }catch(e){} $element.attr("completebox","true"); } searchPage(selectorElementList){ if(!this.intervalIsRunComplete){ return; } selectorElementList.forEach((elementData)=>{ if(!!elementData){ this.createAllElementHtml(elementData); } }); } start(){ const selectorElementList = this.pickupSearchElements(); setInterval(()=>{ this.searchPage(selectorElementList); }, 500); }; } (new searchEnginesNavigation()).start(); (new Coupon()).start(); (new SearchPageObject()).start(); })();