// ==UserScript== // @name 京东秒杀价格过滤 // @namespace http://tampermonkey.net/ // @version 0.1 // @icon https://www.jd.com/favicon.ico // @description 按价格过滤并排序(价格升序)秒杀商品列表 // @author You! // @run-at document-end // @match *://miaosha.jd.com/category.html?cate_id=* // @grant GM_setValue // @grant GM_getValue // @downloadURL none // ==/UserScript== GM_setValue('jd_miaosha_price_min', 0.00); //<-----------------------------------------------------------过滤价格修改这里 GM_setValue('jd_miaosha_price_max', 100.00); //<-----------------------------------------------------------过滤价格修改这里 (function() { var doFilter = function(){ clearInterval(priceFilter); var count = 0; //count += filterGoods($('div.skwrap')); //正在抢购 //count += filterGoods($('div.moregoods')); //更多好货 count += filterGoods($('div.catinfo_seckillnow')); //当天正在秒杀的商品 count += filterGoods($('div.catinfo_startsoon')); //明日秒杀的商品 if (count === 0) priceFilter = setInterval(doFilter, 1000); }; var filterGoods = function(goodsList) { var goods = goodsList.find('li.seckill_mod_goods'); if (goods.length > 0) { //按价格过滤 var niceGoods = []; goods.each(function(idx){ var price = getPrice(this); if (priceMin <= price && price <= priceMax) niceGoods.push(this); }); var count = niceGoods.length; if (count > 0) { //排序 $(niceGoods[0].closest('ul')).empty().append(niceGoods.sort(function(g1, g2){ return getPrice(g1) - getPrice(g2); //<-----------------------------------------------------------如果要降序,修改这里 })); } } return goods.length; }; if (!location.href.match('miaosha.jd.com')) return; var priceMin = GM_getValue('jd_miaosha_price_min'); var priceMax = GM_getValue('jd_miaosha_price_max'); var priceFilter = setInterval(doFilter, 1000); })(); function getPrice(elm) { return getFloat($(elm).find('i.seckill_mod_goods_price_now').first().text()); } function getFloat(str) { str = str.replace('¥','').replace('¥','').trim(); if (!/^\d+\.?\d*$/.test(str)) return NaN; return parseFloat(str); }