淘宝销量排序

在淘宝天猫浏览商品时,自动为你首选 [按销量排序]。方便实用!

目前為 2015-12-04 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         淘宝销量排序
// @namespace    http://hzy.pw
// @description  在淘宝天猫浏览商品时,自动为你首选 [按销量排序]。方便实用!
// @authuer      Moshel
// @homepageURL  http://hzy.pw/p/1364
// @license      Apache License 2.0
// @supportURL   http://weibo.com/moshel
// @icon         http://hzy.pw/wp-content/uploads/2015/08/i-300x300.jpg

// @include      *.taobao.com/*
// @include      *.tmall.com/*
// @grant        none
// @run-at       document_start

// @date         8/5/2015
// @modified     12/4/2015
// @version      1.3
// ==/UserScript==


!function(){

	var href = window.location.href;
	if ( href.indexOf("buy.taobao.com") < 0 && href.indexOf("login.taobao.com") < 0 ){ /* 不支持这些界面 */
		
		var href0 = href;

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


		if ( href.indexOf("?")>0 && href.indexOf("orderType=") < 0 ) /* 天猫淘宝店铺内搜索&分类浏览 */
			href += "&orderType=hotsell_desc";
			
		if ( href.indexOf("list.tmall.com/")>0 ) { /* 天猫搜索 */
			if ( href.indexOf("&sort=") < 0 )
				href += "&sort=d";
		}
		else if( href.indexOf("s.taobao.com/")>0 ) { /* 淘宝搜索 */
			if ( href.indexOf("&sort=") < 0 )
				href += "&sort=sale-desc";
		}


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

		/* 进行跳转 */
		if ( href != href0 )
			window.location.href = href;

	} /* end if not buying page */

}();