Nexus Clash Enchanting Aid

Helps track an items enchantment history.

目前為 2015-09-25 提交的版本,檢視 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name        Nexus Clash Enchanting Aid
// @namespace   http://userscripts.org/users/125692
// @description Helps track an items enchantment history.
// @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     0.5
// @grant GM_addStyle
// @grant GM_setValue
// @grant GM_getValue
// ==/UserScript==

//What we want to do.
//catch all enchant attempts. get object id and store the id and the enchant type.
//must also catch failures to enchant and - the attempt.
//then on load we add to inventory item the count and type of the last 10 enchants on that item.

//this copied off the web
//http://stackoverflow.com/questions/9447950/script-to-save-settings
// for chrome as no GM_getValue and GMsetValue available.
//altered thanks to AuxAuv	
try{	
if (!this.GM_getValue || (this.GM_getValue.toString && this.GM_getValue.toString().indexOf("not supported")>-1)) {
    this.GM_getValue=function (key,def) {
        return localStorage[key] || def;
    };
    this.GM_setValue=function (key,value) {
        return localStorage[key]=value;
    };
    this.GM_deleteValue=function (key) {
        return delete localStorage[key];
    };
  }
} catch (err) { console.log('Test if GM_getValue supported error:\n' + err.message); }



//name='enchanting'
var enchantforms = document.evaluate(
	"//form[@name='enchanting'] ", 
	document, 
	null,
	XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,
	null
);
if (enchantforms.snapshotLength>0){
//we have one form assume its the one form so then add event listenr to it to capture the object id of the enchanted item.
//set up the event to place on the enchant button
	var enchantevent=function(e) {
		var ebutton=e.target;
		//alert("running"+ebutton.value);
		//var enchantform=ebutton.parentNode;
    //alert("running"+enchantform.innerHTML);
		var enchantformitem=ebutton.nextElementSibling;
		//alert("running"+enchantformitem.innerHTML);
		var enchantformenchantment=enchantformitem.nextElementSibling;
		//alert("running"+enchantformenchantment.innerHTML);
		var itemid =enchantformitem[enchantformitem.selectedIndex].value;
		//alert("running"+itemid);
		var enchanttype =enchantformenchantment[enchantformenchantment.selectedIndex].value; 
        var enchanthistory=GM_getValue(''+itemid,"??????????");//get the history of this item or make new blank
		switch(enchanttype){
			case'accuracy':
			case'defense':
			case'accuracy/defense':itemcode='a';break;
			case'acid':itemcode='b';break;
			case'arcane':itemcode='c';break;
			case'cold':itemcode='d';break;
			case'death':itemcode='e';break;
			case'durability':itemcode='f';break;
			case'electric':itemcode='g';break;
			case'fire':itemcode='h';break;
			case'holy':itemcode='i';break;
			case'lighten':itemcode='j';break;
			case'poison':itemcode='k';break;
			case'unholy':itemcode='l';break;
			default:itemcode='?';break;
		}
		enchanthistory=enchanthistory.substr(1)+itemcode;//we only want a 10 long history. Drop first letter & append new letter
		GM_setValue(''+itemid,enchanthistory);
	}
	//append the listener to the enchant button.  Note at the moment no care is taken to ensure we have succeeded. So it's a bit shit at the moment.
  enchantforms.snapshotItem(0).firstElementChild.addEventListener("click",enchantevent,true);
	var itemselect=enchantforms.snapshotItem(0).firstElementChild.nextElementSibling;
	var itemcount=itemselect.length;
	var test 
	function decodeenchant(enchantstring){
		//var a=split(enchantstring);
		var output='| ';
		var testchar;
		for(var j=0;testchar=enchantstring[j];j++){
			//alert(enchantstring+":"+j+":"+testchar);
			switch(testchar){
				case'a':output+='accuracy/defense';break;
				case'b':output+='acid';break;
				case'c':output+='arcane';break;
				case'd':output+='cold';break;
				case'e':output+='death';break;
				case'f':output+='durability';break;
				case'g':output+='electric,';break;
				case'h':output+='fire';break;
				case'i':output+='holy';break;
				case'j':output+='lighten';break;
				case'k':output+='poison';break;
				case'l':output+='unholy';break;
				case'?':
				default:output+='-';break;
			}
			output+=" | ";
		}
		return output+"<-Latest enchantment";
	}
	var decodetext="";
	for(var i=0;i<itemcount;i++){
			test=GM_getValue(itemselect[i].value,"");
			if(test!=""){
			decodetext=decodeenchant(test);	
			itemselect[i].title=decodetext;	
			//and we ought to add it as title text to the inventory.
			var inventoryheaders = document.evaluate(
				"//th[starts-with(.,'Item')]", 
				document, 
				null,
				XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,
				null
				);
			if(inventoryheaders.snapshotLength>0){
				var inventoryheader=inventoryheaders.snapshotItem(0);
				document.evaluate(
				".//tr[td/a[contains(@href,'item="+itemselect[i].value+"')]]",
				inventoryheader.parentNode.parentNode, 
				null,
				XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,
				null
				).snapshotItem(0).title=decodetext;	
			}
		  }
	}
}