Nexus Clash Remove Spell Gem Color

In the faction safe removes the color from spell gems and resorts them alphabetically

当前为 2014-08-24 提交的版本,查看 最新版本

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

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

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。

您需要先安装用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name           Nexus Clash Remove Spell Gem Color
// @namespace      http://userscripts.org/users/125692
// @description    In the faction safe removes the color from spell gems and resorts them alphabetically
// @include        http://nexusclash.com/modules.php?name=Game*
// @include        http://www.nexusclash.com/modules.php?name=Game*
// @exclude        http://nexusclash.com/modules.php?name=Game&op=disconnect
// @exclude        http://www.nexusclash.com/modules.php?name=Game&op=disconnect
// @version 1.0
// @grant none
// ==/UserScript==
// 1.0   --- sorting is case insensitive.
(function() {
//some functions
//capitalize first word come across
//function ucfirstletter(str){
//return str.replace(/\b[A-Za-z]/,function($0) { return $0.toUpperCase(); })
//}

//sort a select
//sorts alphabetical of first word of option text
function sortSelect(selElem) {
		var tmpAry = new Array();
        var sellength=selElem.options.length;
		for (var i=0;i<sellength ;i++) {
			tmpAry[i] = new Array();
			tmpAry[i][0] = selElem.options[i].text.replace(/Small [A-Za-z]+ Gem -/,"Spellgem -");//strip color
			tmpAry[i][1] = selElem.options[i].value;
            tmpAry[i][2] = selElem.options[i].selected;
            tmpAry[i][3] = selElem.options[i].className;
		}
		tmpAry.sort(function (a,b){//this needed to ignore case and leading numbers
                var a=a[0].match(/([A-Za-z-,0-9 ]+)/)[1].toLowerCase();
                var b=b[0].match(/([A-Za-z-,0-9 ]+)/)[1].toLowerCase();//([A-Za-z-,0-9 ]+)
                return a<b?-1:b<a?1:0;
            });
		for (var i=0;i<tmpAry.length;i++) {
            selElem.options[i].text=tmpAry[i][0];
            selElem.options[i].value=tmpAry[i][1];
            selElem.options[i].selected=tmpAry[i][2];
            selElem.options[i].className=tmpAry[i][3];
		}
		return;
	}

//find the safe select
var factionsafe=document.evaluate( "//form[@name='footlockergrab']", document, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);

if (factionsafe.snapshotLength>0){//so we found one. assume its what we want and continue;
    var factionsafeselect=factionsafe.snapshotItem(0).lastElementChild;//should be faction safe.
//resort select which also strips the spell gem colors
    sortSelect(factionsafeselect);

}
//Small Green Gem, 3 shots (5)
//Small Red Gem - Battering Ram, 2 shots (1)
//EOF
})();