// ==UserScript== // @name 京东自营过滤 // @version 0.2.0.8 // @icon https://www.jd.com/favicon.ico // @description 在京东商品列表和搜索结果页面增加【自营】【非自营】过滤选项。京东的商品分类列表页和搜索结果列表页过滤器中的【京东配送】和【自营】是不一样的,【京东配送】会包含部分第三方商家的商品,只是由京东承担物流运输而已,这些第三方商品很多都没有“上午下单下午就到”的快捷,所以有必要专门针对【自营】和【非自营】过滤商品列表!但是需要注意的是,有些【自营】商品也是由【厂商配送】的,这种商品可以通过同时选中【自营】和【京东配送】过滤掉。 // @author You! // @grant GM_setValue // @grant GM_getValue // @grant GM_deleteValue // @grant GM_addStyle // @include *://list.jd.com/list.html?* // @include *://search.jd.com/search?* // @include *://search.jd.com/Search?* // @run-at document-end // @namespace https://greasyfork.org/zh-CN/scripts/33729-京东自营过滤 // @downloadURL none // ==/UserScript== (function() { 'use strict'; //扫描页面的间隔频率时间 var timerFreq = 300; //var goodsJdKey = 'jd_' + location.pathname.split(/[\/\.]/)[1].toLowerCase() + '_' + location.search.split(/[\?&]/)[1].replace(/[=,]/g, '_').toLowerCase() + '_goodsJd'; //var goods3rdKey = 'jd_' + location.pathname.split(/[\/\.]/)[1].toLowerCase() + '_' + location.search.split(/[\?&]/)[1].replace(/[=,]/g, '_').toLowerCase() + '_goods3rd'; //上面两行替换下面两行可以对每个商品分类列表和搜索关键词独立保存过滤器设置 var goodsJdKey = 'jd_goodsJd'; var goods3rdKey = 'jd_goods3rd'; var currentPathname = location.pathname.toLowerCase(); runMain(); //页面入口点 function runMain() { switch(currentPathname) { case '/search': if ($('span.ns-icon').length == 1) return; //搜索没有结果 } uiInit(); loadAllGoods(); } //向页面添加自营过滤选项 function uiInit() { var uiPos = $('.f-feature ul'); if (uiPos.length > 0) { switch(currentPathname) { case '/search': uiPos.find('li a[onclick]').each(function() { var tagA = $(this); var oldOnClick = this.onclick; tagA.click(function() { oldOnClick(); var waitAjaxLoadGoodsList = function() { if (unsafeWindow.SEARCH.loading) setTimeout(waitAjaxLoadGoodsList, timerFreq); else runMain(); }; setTimeout(waitAjaxLoadGoodsList, timerFreq); }); tagA.removeAttr('onclick'); }); var hookSearchSort = function() { var sortA = $('#J_filter div.f-sort a[onclick]'); if (unsafeWindow.SEARCH !== undefined && unsafeWindow.SEARCH.sort_html !== undefined) { var oldSortHtml = unsafeWindow.SEARCH.sort_html; unsafeWindow.SEARCH.sort_html = function(C) { oldSortHtml(C); $('#J_filter div.f-sort a[onclick]').each(function() { var tagA = $(this); var oldOnClick = this.onclick; tagA.click(function() { oldOnClick(); var waitAjaxLoadGoodsList = function() { if (unsafeWindow.SEARCH.loading) setTimeout(waitAjaxLoadGoodsList, timerFreq); else loadAllGoods(); }; setTimeout(waitAjaxLoadGoodsList, timerFreq); }); tagA.removeAttr('onclick'); }); }; } else setTimeout(hookSearchSort, timerFreq); }; hookSearchSort(); break; } var goodsJdChecked = GM_getValue(goodsJdKey) === undefined ? 'class="selected"' : ''; var goods3rdChecked = GM_getValue(goods3rdKey) === undefined ? 'class="selected"' : ''; GM_addStyle('.goodsCount{font-size:10px;color:#fff;background-color:#e23a3a;border-radius:3px;padding:0px 3px;margin:0 5px 0 2px}'); uiPos.first().prepend($( '