// ==UserScript== // @name 京东秒杀价格过滤 // @version 0.3.0.5 // @icon https://www.jd.com/favicon.ico // @description 按价格过滤并排序(价格升序)秒杀商品列表 // @author You! // @grant GM_setValue // @grant GM_getValue // @grant GM_deleteValue // @match *://miaosha.jd.com/pinpai.html?brand_id=* // @match *://miaosha.jd.com/brand.html?brand_id=* // @match *://miaosha.jd.com/category.html?cate_id=* // @run-at document-end // @namespace https://greasyfork.org/zh-CN/scripts/33454-京东秒杀价格过滤 // @downloadURL none // ==/UserScript== (function() { 'use strict'; /**********************************************************/ //如果要过滤商品名,启用该函数,但是需要自己实现过滤逻辑: // pname 传入商品名 // catId 传入商品分类编号,编号代表的意义请自行对照京东秒杀的页面地址 // 命中返回 true, 否侧返回 false /*在行首插入单行注释(//)以启用该商品名过滤函数*/ function filterPName(pname, cat, catId) { switch(cat) { case 'pinpai': //品牌秒杀 break; case 'brand': //品类秒杀 break; case 'category': //分类秒杀 if (catId == 34) { //潮流鞋靴 if (!pname.match('男')) return false; } break; } return true; } /**********************************************************/ if (!location.href.match('miaosha.jd.com')) return; //扫描页面的间隔频率时间 var timerFreq = 1000; var currentPageKey = 'jd_miaosha_' + location.pathname.split(/[\/\.]/)[1] + '_' + location.search.split('&')[0].split('=')[1]; var priceInfo = loadPagePrice(currentPageKey); uiInit(); doFilter(); //向页面右下角的浮动工具栏尾部追加价格过滤部件 function uiInit() { var uiPos = $('#sk_mod_er'); if (uiPos.length > 0) { var checked = priceInfo.checked ? ' checked="true"' : ''; uiPos.append($( '
' )); var onPriceChange = function() { setTimeout(function() { saveCurrentPagePrice(); }, 0); }; $('#fltReload').first().click(onPriceChange); $('#fltPriceMin').first().change(onPriceChange); $('#fltPriceMax').first().change(onPriceChange); $('#fltPriceOne').first().click(function() { var oldChecked = !this.checked; setTimeout(function() { saveCurrentPagePrice(oldChecked); $('#fltPriceMin').attr('value', priceInfo.min); $('#fltPriceMax').attr('value', priceInfo.max); }, 0); }); } else setTimeout(uiInit, timerFreq); } //对页面执行过滤排序操作 function doFilter() { var count = 0; switch(location.pathname) { case '/': //秒杀首页 //count += filterGoods($('div.skwrap')); //正在抢购 //count += filterGoods($('div.moregoods')); //更多好货 break; case '/pinpai.html': //品牌秒杀 case '/brand.html': //品类秒杀 count += filterGoods($('div.bprd')); break; case '/category.html': //分类秒杀 count += filterGoods($('div.catinfo_seckillnow')); //当天正在秒杀的商品 count += filterGoods($('div.catinfo_startsoon')); //明日秒杀的商品 break; } if (count === 0) setTimeout(doFilter, timerFreq); } //对页面内的一个具体分类执行过滤排序操作 function filterGoods(goodsList) { var goods = goodsList.find('li.seckill_mod_goods'); if (goods.length > 0) { var niceGoods = []; goods.each(function(idx){ //按商品名过滤 if (typeof(filterPName) === 'function') { var pname = getProductName(this); if (!filterPName(pname, priceInfo.pageCat, priceInfo.pageCatId)) return; } //按价格过滤 var price = getPrice(this); if (price.now < priceInfo.min || (0 < priceInfo.max && priceInfo.min <= priceInfo.max && priceInfo.max < price.now)) return; //标注优惠力度 var priceOff = price.pre - price.now; var discount = price.now / price.pre; if (discount <= 0.1) { $(this).find('div.seckill_mod_goods_info').attr('title', '1折以下(优惠'+priceOff+')').css('background-color', 'gold'); //1折以下 } else if (discount <= 0.3) { $(this).find('div.seckill_mod_goods_info').attr('title', '3折以下(优惠'+priceOff+')').css('background-color', 'springgreen'); //3折以下 } else if (discount <= 0.5) { $(this).find('div.seckill_mod_goods_info').attr('title', '5折以下(优惠'+priceOff+')').css('background-color', '#BBFFEE'); //5折以下 } else if (discount <= 0.75) { $(this).find('div.seckill_mod_goods_info').attr('title', '75折以下(优惠'+priceOff+')').css('background-color', '#CCEEFF'); //75折以下 } else if (priceOff >= 90) { $(this).find('div.seckill_mod_goods_info').attr('title', '优惠超过90('+priceOff+')').css('background-color', '#FFEEEE'); //优惠超过90 } //命中 niceGoods.push(this); }); //排序 if (niceGoods.length > 0) { niceGoods.sort(function(g1, g2){ return getPrice(g1).now - getPrice(g2).now; //<---------------------------------------如果要降序,修改这里 }); //取消图片延迟加载 forceLoadLazyImgs(niceGoods); } else niceGoods = $('