// ==UserScript== // @name 咸鱼助手 // @namespace http://tampermonkey.net/ // @version 0.1 // @description 改变移动端二维码出现位置,删除下载推广连接,删除修正咸鱼宝贝图片的大小 // @author ruibty // @require https://cdn.bootcss.com/jquery/3.1.1/jquery.min.js // @match https://2.taobao.com/* // @match https://s.2.taobao.com/* // @grant none // @downloadURL none // ==/UserScript== (function() { 'use strict'; // Your code here... var locationPage = "home"; if(document.URL.indexOf("taobao.com/list") != -1){ //搜索列表 locationPage = "list"; }else if(document.URL.indexOf("taobao.com/item") != -1){ //宝贝详情页 locationPage = "item"; } var assistant = { ready : function(){ switch(locationPage){ case "home": break; case "list": assistant.removeXYGuide(); break; case "item": assistant.removeTheMauGuide(); assistant.removeXYGuide(); assistant.removeGuarantee(); assistant.removeIdleFooter(); assistant.setDisplayContact(); break; default: break; } }, onload : function(){ switch(locationPage){ case "home": break; case "list": assistant.changeImgWidthAndHeight(); break; case "item": break; default: break; } assistant.removeTheDownloadLayer(); }, removeTheMauGuide : function(){ //去掉宝贝轮播图第一张碍眼的遮挡文字,放到最后 var imgSrc = $('.guide-img').attr("src"); $('.mau-guide').remove(); //放到轮播图最后 var lastLi = $('ul[class="album"] li:last'); var reg = /(?<=(lazyload-img="))[^"]*?(?=")/ig; var guideHtml = lastLi[0].outerHTML.replace(reg, imgSrc); $('ul[class="album"]').append(guideHtml); //处理thumb var thumbUl = $('.thumb-list ul'); var thumbUlLastLiHtml = thumbUl.children('li')[0].outerHTML; var thumbReg = /(?<=(src="))[^"]*?(?=")/ig; thumbUl.append(thumbUlLastLiHtml.replace(thumbReg, imgSrc)); }, removeTheDownloadLayer : function(){ //宝贝详情页-去掉遮挡推广链接 $('.download-layer').remove(); }, removeXYGuide : function(){ //宝贝详情页-去掉介绍页咸鱼app的推广广告 $('.xy-guide').remove(); }, removeGuarantee : function(){ //宝贝详情页-去掉“安全保障”说明 $('#guarantee').remove(); }, removeIdleFooter : function(){ //宝贝详情页-去掉底部灰色的淘宝官方推广 $('.idle-footer').remove(); }, setDisplayContact : function(){ //宝贝详情页-增加联系窗口 $('.contact div').show(); }, changeImgWidthAndHeight : function(){ //修正图片的大小 $('img').each(function(){ var imgSrc = $(this).attr("src"); if(imgSrc && imgSrc.length >= 3){ var imgSrcEnd = imgSrc.substr(imgSrc.length - 3, imgSrc.length); if(imgSrcEnd == "jpg"){ var imgWidth = $(this)[0].naturalWidth //图片真实宽度 var imgHeight = $(this)[0].naturalHeight //图片真实高度 $(this).attr("width",imgWidth); $(this).attr("height",imgHeight); } } }); } } function changeState() { if(document.readyState == "complete"){ console.log("测试测试"); assistant.changeImgWidthAndHeight(); } } document.onreadystatechange = changeState; $(function(){ assistant.ready(); }); window.onload = function(){ assistant.onload(); } })();