自动京东配送

在京东浏览商品时,可选择自动为你勾选 [京东配送]、[仅显示有货]、[销量排序]。方便实用!

Från och med 2016-03-22. Se den senaste versionen.

// ==UserScript==
// @name         自动京东配送
// @namespace    http://hzy.pw
// @description  在京东浏览商品时,可选择自动为你勾选 [京东配送]、[仅显示有货]、[销量排序]。方便实用!
// @authuer      Moshel
// @homepageURL  http://hzy.pw/p/1349
// @supportURL   http://weibo.com/moshel
// @icon         http://hzy.pw/wp-content/uploads/2015/04/i.jpeg

// @include      http://list.jd.com/*
// @include      http://search.jd.com/*
// @grant        none
// @run-at       document_start

// @version      2.2.1
// ==/UserScript==


! function() {
    "use strict";

    var href = window.location.href;

    if( href.indexOf("fixedByTool") < 0 ){
    	/* 首先去除掉末尾的 # 信息 */
    	var suzu = href.split("#", 2);
    	if ( suzu.length == 2 )
    	{
    		href = suzu[0];
    		var fixed = true;
    	}
    	else
    		var fixed = false;

    	href += "&fixedByTool=1";

    	/* 不存在开关,直接添加打开 */
    	if ( location.search.indexOf("delivery") < 0 )
    		href += "&delivery=1";
    	if ( location.search.indexOf("stock") < 0 )
    		href += "&stock=1";
    	if ( location.search.indexOf("wtype") < 0 ) /* 图书页面的京东配送 */
    		href += "&wtype=1";
    	if ( location.search.indexOf("psort") < 0 ) /* 销量排序 */
    		href += "&psort=3";

    	/* 还原 # 信息 */
    	if ( fixed )
    		href += "#" + suzu[1];

    	window.location.href = href;
    }

}();