HRPG+

Improved Heroes RPG GUI

目前为 2015-10-10 提交的版本。查看 最新版本

// ==UserScript==
// @name        HRPG+
// @namespace   HRPG
// @description Improved Heroes RPG GUI
// @include     http://heroesrpg.com/game.php*
// @include     http://www.heroesrpg.com/game.php*
// @version     1.1.6.6
// @grant       none
// ==/UserScript==
// multiple skills, gem bonuses from accs/weps, notify update
// change tab title to CAPTCHA
$('#chat1').prepend(/*`<input type="submit" value="Cancel Autobuy" onclick="javascript:autoDo = false;"></input> */`Volume: <input id="volume" type="number" min="0" max="100" value="100" width="30" size="3"></input> <input type="checkbox" id="riftAlerts" checked="${window.localStorage.getItem('riftAlerts')||false?'checked':'none'}"></input> Nugget's RiftAlert™`);
//todo: calculate max autos, sell all accessories
$('#riftAlerts').change(function () {localStorage.setItem('riftAlerts',$('#riftAlerts').is(':checked'));});
$('body').append('<script>Array.prototype.after = function (o){return this[this.indexOf(o)+1];}\nString.prototype.replaceAt = function(n, t) {return this.substring(0, n) + t + this.substring(n + 1);}</script>');

//window.autoDo = true;

window.rarityNum = new Object();
window.rarityNum.common = 1;
window.rarityNum.uncommon = 2;
window.rarityNum.rare = 3;
window.rarityNum.epic = 4;
window.rarityNum.legendary = 5;

window.command = new Object();
window.command.c = 'Posts <message> to clan chat.'
window.command.t = 'Posts <message> to trade chat.'
window.command.double = 'Shows length of double and haste remaining.'
window.command.haste = 'Shows length of double and haste remaining.'
window.command.commands = 'Shows a list of commands.'
window.command.command = 'Shows information about <commandname>.'
window.command.profile = 'Shows profile of <username>.'
window.command.who = 'Shows basic information of <username>.'
window.command.misc = 'Shows battles and quests of <username>.'
window.command.crafting = 'Shows crafting levels of <username>.'
window.command.gathering = 'Shows gathering levels of <username>.'
window.command.pick = 'Picks <number> <rarity> chests.'
window.command.pickall = 'Picks all <rarity> chests.'
window.command.boosts = 'Shows your boosts.'
window.command.buyboost = 'Buys <number> <name> boosts.'
window.command.buyauto = 'Buys <number> autos.'

window.boosts = new Object();
window.boosts.battleexp = 1;
window.boosts.gold = 2;
window.boosts.attribute = 3;
window.boosts.battlesp = 4;
window.boosts.gatheringexp = 5;
window.boosts.gatheringsp = 6;

//Start Showdown

window.g_list_level = 0;

window.makeHtml = function(text) {
	g_urls = [];
	g_titles = [];
	g_html_blocks = [];
	text = text.replace(/~/g,"~T");
	text = text.replace(/\$/g,"~D");
	text = text.replace(/\r\n/g,"\n");
	text = text.replace(/\r/g,"\n");
	text = _Detab(text);
	text = text.replace(/^[ \t]+$/mg,"");
	text = _HashHTMLBlocks(text);
	text = _StripLinkDefinitions(text);
	text = _RunBlockGamut(text);
  text = _RunSpanGamut(text);
	text = _UnescapeSpecialChars(text);
	text = text.replace(/~D/g,"$$");
	text = text.replace(/~T/g,"~");
	return text;
}

window._StripLinkDefinitions = function(text) {
	var text = text.replace(/^[ ]{0,3}\[(.+)\]:[ \t]*\n?[ \t]*<?(\S+?)>?[ \t]*\n?[ \t]*(?:(\n*)["(](.+?)[")][ \t]*)?(?:\n+|\Z)/gm,
		function (wholeMatch,m1,m2,m3,m4) {
			m1 = m1.toLowerCase();
			g_urls[m1] = _EncodeAmpsAndAngles(m2);  // Link IDs are case-insensitive
			if (m3) { return m3+m4; } else if (m4) { g_titles[m1] = m4.replace(/"/g,"&quot;"); 			}
			return "";
		});
	return text;
}

window._HashHTMLBlocks = function(text) {
	text = text.replace(/\n/g,"\n\n");
	block_tags_a = "p|div|h[1-6]|blockquote|pre|table|dl|ol|ul|script|noscript|form|fieldset|iframe|math|ins|del"
	block_tags_b = "p|div|h[1-6]|blockquote|pre|table|dl|ol|ul|script|noscript|form|fieldset|iframe|math"
	text = text.replace(/^(<(p|div|h[1-6]|blockquote|pre|table|dl|ol|ul|script|noscript|form|fieldset|iframe|math|ins|del)\b[^\r]*?\n<\/\2>[ \t]*(?=\n+))/gm,hashElement);
	text = text.replace(/^(<(p|div|h[1-6]|blockquote|pre|table|dl|ol|ul|script|noscript|form|fieldset|iframe|math)\b[^\r]*?.*<\/\2>[ \t]*(?=\n+)\n)/gm,hashElement);
	text = text.replace(/(\n[ ]{0,3}(<(hr)\b([^<>])*?\/?>)[ \t]*(?=\n{2,}))/g,hashElement);
	text = text.replace(/(\n\n[ ]{0,3}<!(--[^\r]*?--\s*)+>[ \t]*(?=\n{2,}))/g,hashElement);
	text = text.replace(/(?:\n\n)([ ]{0,3}(?:<([?%])[^\r]*?\2>)[ \t]*(?=\n{2,}))/g,hashElement);
	text = text.replace(/\n\n/g,"\n");
	return text;
}

window.hashElement = function(wholeMatch,m1) {
	blockText = m1;
	blockText = blockText.replace(/\n\n/g,"\n");
	blockText = blockText.replace(/^\n/,"");
	blockText = blockText.replace(/\n+$/g,"");
	blockText = "~K" + (g_html_blocks.push(blockText)-1).toString() + "K";
	return blockText;
}

window._RunBlockGamut = function(text) {
	text = _DoHeaders(text);
	var key = hashBlock("<hr />");
	text = text.replace(/^[ ]{0,2}([ ]?\*[ ]?){3,}[ \t]*$/gm,key);
	text = text.replace(/^[ ]{0,2}([ ]?\-[ ]?){3,}[ \t]*$/gm,key);
	text = text.replace(/^[ ]{0,2}([ ]?\_[ ]?){3,}[ \t]*$/gm,key);
	text = _DoLists(text);
	text = _DoCodeBlocks(text);
	text = _DoBlockQuotes(text);
	text = _HashHTMLBlocks(text);
	text = _FormParagraphs(text);
	return text;
}

_FormParagraphs = function(text, doNotUnhash) {
	text = text.replace(/^\n+/g,'');
	text = text.replace(/\n+$/g,'');
	grafs = text.split(/\n{2,}/g);
	grafsOut = new Array();
	end = grafs.length;
	for (i = 0; i < end; i++) {
		str = grafs[i];
		if (str.search(/~K(\d+)K/g) >= 0) { grafsOut.push(str); }
		else if (str.search(/\S/) >= 0) {
			str = _RunSpanGamut(str);
			str = str.replace(/^([ \t]*)/g,'');
			grafsOut.push(str);
		}
	}
  end = grafsOut.length;
	  for (i=0; i<end; i++) {
	    while (grafsOut[i].search(/~K(\d+)K/) >= 0) {
		    var blockText = g_html_blocks[RegExp.$1];
			    blockText = blockText.replace(/\$/g,"$$$$"); // Escape any dollar signs
			    grafsOut[i] = grafsOut[i].replace(/~K\d+K/,blockText);
	    }
	  }
	return grafsOut.join('/n/n');
}

window._RunSpanGamut = function(text) {
	text = _DoCodeSpans(text);
	text = _EscapeSpecialCharsWithinTagAttributes(text);
	text = _EncodeBackslashEscapes(text);
	text = _DoImages(text);
	text = _DoAnchors(text);
	text = _DoAutoLinks(text);
	text = _EncodeAmpsAndAngles(text);
	text = _DoItalicsAndBold(text);
	text = text.replace(/  +\n/g," <br />\n");
	return text;
}

window._EscapeSpecialCharsWithinTagAttributes = function(text) {
	var regex = /(<[a-z\/!$]("[^"]*"|'[^']*'|[^'">])*>|<!(--.*?--\s*)+>)/gi;
	text = text.replace(regex, function(wholeMatch) {
		var tag = wholeMatch.replace(/(.)<\/?code>(?=.)/g,"$1`");
		tag = escapeCharacters(tag,"\\`*_");
		return tag;
	});
	return text;
}

window._DoAnchors = function(text) {
	text = text.replace(/(\[((?:\[[^\]]*\]|[^\[\]])*)\][ ]?(?:\n[ ]*)?\[(.*?)\])()()()()/g,writeAnchorTag);
	text = text.replace(/(\[((?:\[[^\]]*\]|[^\[\]])*)\]\([ \t]*()<?(.*?)>?[ \t]*((['"])(.*?)\6[ \t]*)?\))/g,writeAnchorTag);
	text = text.replace(/(\[([^\[\]]+)\])()()()()()/g, writeAnchorTag);
	return text;
}

window.writeAnchorTag = function(wholeMatch,m1,m2,m3,m4,m5,m6,m7) {
	if (m7 == undefined) m7 = "";
	var whole_match = m1;
	var link_text   = m2;
	var link_id	 = m3.toLowerCase();
	var url		= m4;
	var title	= m7;
	if (url == "") {
		if (link_id == "") { link_id = link_text.toLowerCase().replace(/ ?\n/g," "); }
		url = "#"+link_id;
		if (g_urls[link_id] != undefined) {
			url = g_urls[link_id];
			if (g_titles[link_id] != undefined) { title = g_titles[link_id]; }
		}
		else { if (whole_match.search(/\(\s*\)$/m)>-1) { url = ""; } else { return whole_match; } }
	}
	url = escapeCharacters(url,"*_");
	var result = "<a href=\"" + url + "\"";
	if (title != "") {
		title = title.replace(/"/g,"&quot;");
		title = escapeCharacters(title,"*_");
		result +=  " title=\"" + title + "\"";
	}
	result += ">" + link_text + "</a>";
	return result;
}

window._DoImages = function(text) {
	text = text.replace(/(!\[(.*?)\][ ]?(?:\n[ ]*)?\[(.*?)\])()()()()/g,writeImageTag);
	text = text.replace(/(!\[(.*?)\]\s?\([ \t]*()<?(\S+?)>?[ \t]*((['"])(.*?)\6[ \t]*)?\))/g,writeImageTag);
	return text;
}

window.writeImageTag = function(wholeMatch,m1,m2,m3,m4,m5,m6,m7) {
	whole_match = m1;
	alt_text    = m2;
	link_id	    = m3.toLowerCase();
	url		      = m4;
	title	      = m7;
	if (!title) title = "";
	if (url == "") {
		if (link_id == "") { link_id = alt_text.toLowerCase().replace(/ ?\n/g," "); }
		url = "#"+link_id;
		if (g_urls[link_id] != undefined) {
			url = g_urls[link_id];
			if (g_titles[link_id] != undefined) { title = g_titles[link_id]; }
		}
		else { return whole_match; }
	}
	alt_text = alt_text.replace(/"/g,"&quot;");
	url = escapeCharacters(url,"*_");
	var result = "<img src=\"" + url + "\" alt=\"" + alt_text + "\"";
  title = title.replace(/"/g,"&quot;");
  title = escapeCharacters(title,"*_");
  result +=  " title=\"" + title + "\"";
  result += " />";
  return result;
}

window._DoHeaders = function(text) {
	text = text.replace(/^(.+)[ \t]*\n=+[ \t]*\n+/gm,
		function(wholeMatch,m1){return hashBlock("<h1>" + _RunSpanGamut(m1) + "</h1>");});
	text = text.replace(/^(.+)[ \t]*\n-+[ \t]*\n+/gm,
		function(matchFound,m1){return hashBlock("<h2>" + _RunSpanGamut(m1) + "</h2>");});
	text = text.replace(/^(\#{1,6})[ \t]*(.+?)[ \t]*\#*\n+/gm,
		function(wholeMatch,m1,m2) {
			var h_level = m1.length;
			return hashBlock("<h" + h_level + ">" + _RunSpanGamut(m2) + "</h" + h_level + ">");
		});
	return text;
}

window._ProcessListItems;

window._DoLists = function(text) {
	text += "~0";
	var whole_list = /^(([ ]{0,3}([*+-]|\d+[.])[ \t]+)[^\r]+?(~0|\n{2,}(?=\S)(?![ \t]*(?:[*+-]|\d+[.])[ \t]+)))/gm;
	if (g_list_level) {
		text = text.replace(whole_list,function(wholeMatch,m1,m2) {
			var list = m1;
			var list_type = (m2.search(/[*+-]/g)>-1) ? "ul" : "ol";
			list = list.replace(/\n{2,}/g,"\n\n\n");;
			var result = _ProcessListItems(list);
			result = result.replace(/\s+$/,"");
			result = "<"+list_type+">" + result + "</"+list_type+">\n";
			return result;
		});
	} else {
		whole_list = /(\n\n|^\n?)(([ ]{0,3}([*+-]|\d+[.])[ \t]+)[^\r]+?(~0|\n{2,}(?=\S)(?![ \t]*(?:[*+-]|\d+[.])[ \t]+)))/g;
		text = text.replace(whole_list,function(wholeMatch,m1,m2,m3) {
			var runup = m1;
			var list = m2;
			var list_type = (m3.search(/[*+-]/g)>-1) ? "ul" : "ol";
			var list = list.replace(/\n{2,}/g,"\n\n\n");;
			var result = _ProcessListItems(list);
			result = runup + "<"+list_type+">\n" + result + "</"+list_type+">\n";
			return result;
		});
	}
	text = text.replace(/~0/,"");
  return text;
}

window._ProcessListItems = function(list_str) {
	g_list_level++;
	list_str = list_str.replace(/\n{2,}$/,"\n");
	list_str += "~0";
	list_str = list_str.replace(/(\n)?(^[ \t]*)([*+-]|\d+[.])[ \t]+([^\r]+?(\n{1,2}))(?=\n*(~0|\2([*+-]|\d+[.])[ \t]+))/gm,
		function(wholeMatch,m1,m2,m3,m4){
			var item = m4;
			var leading_line = m1;
			var leading_space = m2;
			if (leading_line || (item.search(/\n{2,}/)>-1)) { item = _RunBlockGamut(_Outdent(item)); }
			else {
				item = _DoLists(_Outdent(item));
				item = item.replace(/\n$/,""); // chomp(item)
				item = _RunSpanGamut(item);
			}
			return  "<li>" + item + "</li>\n";
		}
	);
	list_str = list_str.replace(/~0/g,"");
  g_list_level--;
	return list_str;
}

window._DoCodeBlocks = function(text) {
	text += "~0";
	text = text.replace(/(?:\n\n|^)((?:(?:[ ]{4}|\t).*\n+)+)(\n*[ ]{0,3}[^ \t\n]|(?=~0))/g,
		function(wholeMatch,m1,m2) {
			var codeblock = m1;
			var nextChar = m2;
			codeblock = _EncodeCode( _Outdent(codeblock));
			codeblock = _Detab(codeblock);
			codeblock = codeblock.replace(/^\n+/g,""); // trim leading newlines
			codeblock = codeblock.replace(/\n+$/g,""); // trim trailing whitespace
			codeblock = "<pre><code>" + codeblock + "\n</code></pre>";
			return hashBlock(codeblock) + nextChar;
		}
	);
	text = text.replace(/~0/,"");
	return text;
}

window.hashBlock = function(text) {
	text = text.replace(/(^\n+|\n+$)/g,"");
	return "~K" + (g_html_blocks.push(text)-1).toString() + "K";
}

window._DoCodeSpans = function(text) {
	text = text.replace(/(^|[^\\])(`+)([^\r]*?[^`])\2(?!`)/gm,
		function(wholeMatch,m1,m2,m3,m4) {
			var c = m3;
			c = c.replace(/^([ \t]*)/g,"");	// leading whitespace
			c = c.replace(/[ \t]*$/g,"");	// trailing whitespace
			c = _EncodeCode(c);
			return m1+"<code>"+c+"</code>";
		});
	return text;
}

window._EncodeCode = function(text) {
	text = text.replace(/&/g,"&amp;");
	text = text.replace(/</g,"&lt;");
	text = text.replace(/>/g,"&gt;");
	text = escapeCharacters(text,"\*_{}[]\\",false);
	return text;
}

window._DoItalicsAndBold = function(text) {
	text = text.replace(/(\*\*|__)(?=\S)([^\r]*?\S[*_]*)\1/g,
		"<strong>$2</strong>");
	text = text.replace(/(\w)_(\w)/g, "$1~E95E$2")
	text = text.replace(/(\*|_)(?=\S)([^\r]*?\S)\1/g,
		"<em>$2</em>");
	return text;
}

window._DoBlockQuotes = function(text) {
	text = text.replace(/((^[ \t]*>[ \t]?.+\n(.+\n)*\n*)+)/gm,
		function(wholeMatch,m1) {
			var bq = m1;
			bq = bq.replace(/^[ \t]*>[ \t]?/gm,"~0");
			bq = bq.replace(/~0/g,"");
			bq = bq.replace(/^[ \t]+$/gm,"");
			bq = _RunBlockGamut(bq);
			bq = bq.replace(/(^|\n)/g,"$1  ");
			bq = bq.replace(/(\s*<pre>[^\r]+?<\/pre>)/gm,
				function(wholeMatch,m1) {
					var pre = m1;
					pre = pre.replace(/^  /mg,"~0");
					pre = pre.replace(/~0/g,"");
					return pre;
				});
			return hashBlock("<blockquote>\n" + bq + "\n</blockquote>");
		});
	return text;
}

window._EncodeAmpsAndAngles = function(text) {
	text = text.replace(/&(?!#?[xX]?(?:[0-9a-fA-F]+|\w+);)/g,"&amp;");
	text = text.replace(/<(?![a-z\/?\$!])/gi,"&lt;");
	return text;
}

window._EncodeBackslashEscapes = function(text) {
	text = text.replace(/\\(\\)/g,escapeCharacters_callback);
	text = text.replace(/\\([`*_{}\[\]()>#+-.!])/g,escapeCharacters_callback);
	return text;
}

window._DoAutoLinks = function(text) {
  text = text.replace(/<((https?|ftp|dict):[^'">\s]+)>/gi,"<a href=\"$1\">$1</a>");
	text = text.replace(/<(?:mailto:)?([-.\w]+\@[-a-z0-9]+(\.[-a-z0-9]+)*\.[a-z]+)>/gi,
		function(wholeMatch,m1) {
			return _EncodeEmailAddress( _UnescapeSpecialChars(m1) );
		}
	);
	return text;
}

window._EncodeEmailAddress = function(addr) {
	function char2hex(ch) {
		var hexDigits = '0123456789ABCDEF';
		var dec = ch.charCodeAt(0);
		return(hexDigits.charAt(dec>>4) + hexDigits.charAt(dec&15));
	}
	encode = [
		function(ch){return "&#"+ch.charCodeAt(0)+";";},
		function(ch){return "&#x"+char2hex(ch)+";";},
		function(ch){return ch;}
	];
	addr = "mailto:" + addr;
	addr = addr.replace(/./g, function(ch) {
		if (ch == "@") { ch = encode[Math.floor(Math.random()*2)](ch); } else if (ch !=":") {
			r = Math.random();
			ch =  (r > .9  ?	encode[2](ch):r > .45 ?	encode[1](ch):encode[0](ch));
		}
		return ch;
	});
	addr = "<a href=\"" + addr + "\">" + addr + "</a>";
	addr = addr.replace(/">.+:/g,"\">");
	return addr;
}

window._UnescapeSpecialChars = function(text) {
	text = text.replace(/~E(\d+)E/g,
		function(wholeMatch,m1) {
			var charCodeToReplace = parseInt(m1);
			return String.fromCharCode(charCodeToReplace);
		}
	);
	return text;
}

window._Outdent = function(text) {
	text = text.replace(/^(\t|[ ]{1,4})/gm,"~0");
	text = text.replace(/~0/g,"")
	return text;
}

window._Detab = function(text) {
	text = text.replace(/\t(?=\t)/g,"    ");
	text = text.replace(/\t/g,"~A~B");
	text = text.replace(/~B(.+?)~A/g,
		function(wholeMatch,m1,m2) {
			var leadingText = m1;
			var numSpaces = 4 - leadingText.length % 4;
			for (var i=0; i<numSpaces; i++) leadingText+=" ";
			return leadingText;
		}
	);
	text = text.replace(/~A/g,"    ");
	text = text.replace(/~B/g,"");
	return text;
}

window.escapeCharacters = function(text, charsToEscape, afterBackslash) {
	var regexString = "([" + charsToEscape.replace(/([\[\]\\])/g,"\\$1") + "])";
	if (afterBackslash) { regexString = "\\\\" + regexString; }
	var regex = new RegExp(regexString,"g");
	text = text.replace(regex,escapeCharacters_callback);
	return text;
}

window.escapeCharacters_callback = function(wholeMatch,m1) {
	var charCodeToEscape = m1.charCodeAt(0);
	return "~E"+charCodeToEscape+"E";
}

//End Showdown

window.onlineHTML = function(name){
  online = false;
  $.ajax({type:'POST', url:'misc.php', data:{mod:'playersonlinelist'}, success:function(data) { 
    if($.map($('td',data.v),function(n){return n.textContent;}).indexOf(name) != -1) {online = true;}
  }, dataType:'json', async: false});
  if(online) {return '[ONLINE]';}
  return '<font color="#FFBBBB">[OFFLINE]</font>';
}

/*window.maxAutos = function(credits) {
  //return credits = 10*Math.floor(autos/10)*(Math.floor(autos/10)-1) + 10*((autos/10)%1)*(Math.floor(autos/10))- 30
}*/

window.chatLine = function(msg){
  $('#chat_table1').prepend('<tr id=\"ct1_tr'+(chatid1)+'\"><td>'+msg+'</td></tr>');
  chatid1++;
}

window.send_chat = function(){
  //autoDo = true;
  msg = chatInputElem.val();
  if(msg.toLowerCase() == '/commands'){
    chatLine('<font color="BBFFBB">/c &lt;message&gt;, /t &lt;message&gt;, /double, /haste /commands, /command &lt;commandname&gt;, /pick &lt;rarity&gt; &lt;number&gt;, /pickall &lt;rarity&gt;, /boosts, /buyboost &lt;boostname&gt; &lt;amount&gt;, /buyauto &lt;amount&gt;</font>');
    chatInputElem.val('');
    return;
  }
  if(msg.toLowerCase().startsWith('/command ')){
    commandName=msg.slice(9);
    chatInputElem.val('');
    chatLine(`<font color="BBFFBB">/${commandName}: ${command[commandName].replace('<','&lt;').replace('>','&gt')}</font>`);
    return;
  }
  if(msg.toLowerCase() == '/boosts'){
    $.post('upgrade.php', {mod:'boosts'}, function(data){
      for(i = 2; i < 8; i++){chatLine('<font color="BBFFBB">' + $('td',$('tr',data.v)[i])[0].textContent+': '+$('td',$('tr',data.v)[i])[1].textContent + '</font>');}
	  }, 'json');
    return;
  }
/*  if(msg.toLowerCase().startsWith('/buyboost ')){
    vars = msg.slice(10).split(' ');
    chatInputElem.val('');
    id = boosts[vars[0]];
    amount = Math.min(vars[1],$('#s_credits')[0].textContent/50);
    while (autoDo && amount > 0){
      amount--;
      spendCredits(id,'boost');
    }
    return;
  }
  if(msg.toLowerCase().startsWith('/buyauto ')){
    amount = Math.min(msg.slice(9),$('#s_credits')[0].textContent);
    chatInputElem.val('');
    while (autoDo && amount > 0){
      amount--;
      spendCredits(id,'boost');
    }
    return;
  }
  if(msg.toLowerCase().startsWith('/pick ')){
    vars = msg.slice(6).split(' ');
    rarity = rarityNum[vars[0]];
    chatInputElem.val('');
    if (rarity == undefined) return;
    $('#center_select').val(5);
    centerSelect();
    $('#craft_select')[0].selectedIndex = 4;
    craftSelect();
    console.log(rarity);
    amount = Math.min($('tr','#lockpicking-table')[parseInt(rarity)].childNodes[1].textContent,vars[1]);
    while (autoDo && amount > 9){
      amount -= 10;
      craftPickLock(rarity,2);
    }
    while (autoDo && amount > 0){
      amount--;
      craftPickLock(rarity,1);
    }
    return;
  }
  if(msg.toLowerCase().startsWith('/pickall ')){
    rarity=rarityNum[msg.slice(9)];
    chatInputElem.val('');
    if (rarity == undefined) return;
    $('select#center_select')[0].selectedIndex = 3;
    centerSelect();
    $('select#craft_select')[0].selectedIndex = 4;
    craftSelect();
    while (autoDo && $('tr','#lockpicking-table')[parseInt(rarity)].childNodes[1].textContent > 9) craftPickLock(rarity,2);
    while (autoDo && $('tr','#lockpicking-table')[parseInt(rarity)].childNodes[1].textContent > 0) craftPickLock(rarity,1);
    return;
  }*/
  if(msg.startsWith('/profile ')){
    viewPlayer(msg.slice(9));
    chatInputElem.val('');
    return;
  }
  if(msg.toLowerCase().startsWith('/who ')){
    $.post('misc.php', {mod:'viewplayer', id:msg.slice(5)}, function(data) {
      array = $.map($('td',$('table',data.v).find('tbody')[0]),function(n){return n.textContent;});
      name = array.after('Name:');
      chatLine(`<font color="BBFFBB"><a href="javascript:m('${name}');">${name}</a> - ${$('a',data.v)[0].outerHTML} - Level ${array.after('Level:')} - ${array.after('Nobility Rank:')} - ${onlineHTML(name)} - <a href="javascript:viewPlayer('${name}')">Profile</a></font>`);
    }, 'json');
    chatInputElem.val('');
    return;
  }
  if(msg.toLowerCase().startsWith('/misc ')){
    $.post('misc.php', {mod:'viewplayer', id:msg.slice(6)}, function(data) {
      array = $.map($('td',$('table',data.v).find('tbody')[0]),function(n){return n.textContent;});
      name = array.after('Name:');
      chatLine(`<font color="BBFFBB"><a href="javascript:m('${name}');">${name}</a> - Battles: ${array.after('Battles:')} - Battle Quests: ${array.after('Battle Quests:')} - TS Quests ${array.after('TS Quests:')}</font>`);
    }, 'json');
    chatInputElem.val('');
    return;
  }
  if(msg.toLowerCase().startsWith('/crafting ')){
    $.post('misc.php', {mod:'viewplayer', id:msg.slice(6)}, function(data) {
      array = $.map($('td',$('table',data.v).find('tbody')[0]),function(n){return n.textContent;});
      name = array.after('Name:');
      chatLine(`<font color="BBFFBB"><a href="javascript:m('${name}');">${name}</a> - Forging: ${array.after('Forging:')} - Leatherworking: ${array.after('Leatherworking:')} - Enchanting: ${array.after('Enchanting:')} - Lockpicking: ${array.after('Lockpicking:')} - Jewelcrafing: ${array.after('Jewelcrafting:')}</font>`);
    }, 'json');
    chatInputElem.val('');
    return;
  }
  if(msg.toLowerCase().startsWith('/gathering ')){
    $.post('misc.php', {mod:'viewplayer', id:msg.slice(6)}, function(data) {
      array = $.map($('td',$('table',data.v).find('tbody')[0]),function(n){return n.textContent;});
      name = array.after('Name:');
      chatLine(`<font color="BBFFBB"><a href="javascript:m('${name}');">${name}</a> - Hunting: ${array.after('Hunting:')} - Mining: ${array.after('Mining:')} - Woodcutting: ${array.after('Woodcutting:')} - Quarrying: ${array.after('Quarrying:')}</font>`);
    }, 'json');
    chatInputElem.val('');
    return;
  }
  if(msg.toLowerCase().startsWith('/g ')){msg.replaceAt(2,'c');}
  $.post('chat.php', {mod:'send', msg:msg}, function(data) {
    if(!data.err) {
      if(data.addignore) {ignored.push(data.addignore);}
      if(data.remignore) {ignored.splice(ignored.indexOf(data.remignore, 1));}
      chatInputElem.val('');
      chatinactivity = 0;
      update_chat(0);
    } else { displayError(data.err); }
  }, 'json');
}

/*window.bRightSelect = function() {
  mod = $('#bright_select').val();
  $.post('displayr.php', {mod:mod}, function(data) {
    $('#bright_content').html(data.html);
    if($('select#bright_select')[0].options[$('select#bright_select')[0].selectedIndex].text == 'Items') {
      $('#bright_content').html($('#bright_content').html().replace(/\[<a href="javascript:openChest\((\d),1\)">Open<\/a>\]/g, `<a href="javascript:$('select#center_select')[0].selectedIndex = 3; centerSelect(); $('select#craft_select')[0].selectedIndex = 4; craftSelect(); craftPickLock($1,1);">P</a> <a href="javascript:$('select#center_select')[0].selectedIndex = 3; centerSelect(); $('select#craft_select')[0].selectedIndex = 4; craftSelect(); craftPickLock($1,2);">10</a> <a href="javascript:openChest($1,1);">O</a>`));
    }
  }, 'json');
}*/

window.update_chat = function(initiate) {
  stopActivityTimer();
  startActivityTimer();
  $.post('chatupdate2.php', {initiate:initiate}, function(data) {
    if(data.c) {
      $.each(data.c, function(i, item) {
        if($.inArray(data.c[i].uid, ignored) < 0) {
          chat_table = 1;
          data.c[i].message = makeHtml(data.c[i].message);
          if(data.c[i].type == 1) { msg = '<span class="time">['+data.c[i].time+']</span> '+genrank(data.c[i].nrank, data.c[i].prank)+' '+genStatus(data.c[i].status)+'<a href="javascript:m(\''+data.c[i].cname+'\');">'+data.c[i].cname+'</a>: '+data.c[i].message+'</span>'; }
          else if(data.c[i].type == 0) { msg = '<span class="time">['+data.c[i].time+']</span> <span style="color: #FF8888">'+data.c[i].message+'</span>'; }
          else if(data.c[i].type == 5) { msg = '<span class="time">['+data.c[i].time+']</span> <span style="color: #55AA55">'+data.c[i].message+'</span>'; }
          else if(data.c[i].type == 10) { msg = '<span class="time">['+data.c[i].time+']</span> <span style="color: #88FF88">Global: '+data.c[i].message+'</span>';
            if($('#riftAlerts')[0].checked && data.c[i].message == '<span style="color: #CC66CC">A Rift will open in 5 minutes!</span>') {audio = new Audio('http://cdn.rawgit.com/somebody1234/misc-files/master/rift.mp3');audio.volume=$('#volume')[0].value/100; audio.play();}
						if($('#riftAlerts')[0].checked && data.c[i].message == `<span style="color: #CC66CC">A Rift has opened! The Rift will close in 10 minutes!</span> [<a href="javascript:enterRift()">Enter Rift</a>]`) {audio = new Audio('http://cdn.rawgit.com/somebody1234/misc-files/master/rift.mp3');audio.volume=$('#volume')[0].value/100; audio.play();}}
          else if(data.c[i].type == 1000) { msg = '<span class="time">['+data.c[i].time+']</span> '+genrank(data.c[i].nrank, data.c[i].prank)+' <span style="color: #FFFF00">[Clan] <a href="javascript:m(\''+data.c[i].cname+'\');">'+data.c[i].cname+'</a>: '+data.c[i].message+'</span>'; }
          else if(data.c[i].type == 1001) { msg = '<span class="time">['+data.c[i].time+']</span> <span style="color: #FFFF00">Clan Global: '+data.c[i].message+'</span>'; }
          else if(data.c[i].type == 20) { msg = '<span class="time">['+data.c[i].time+']</span> '+genrank(data.c[i].nrank, data.c[i].prank)+' <span style="color: #9999FF">[Newbie] <a href="javascript:m(\''+data.c[i].cname+'\');">'+data.c[i].cname+'</a>: '+data.c[i].message+'</span>'; }
          else if(data.c[i].type == 30) { msg = '<span class="time">['+data.c[i].time+']</span> '+genrank(data.c[i].nrank, data.c[i].prank)+' <span style="color: #FF9933">[Staff] <a href="javascript:m(\''+data.c[i].cname+'\');">'+data.c[i].cname+'</a>: '+data.c[i].message+'</span>'; }
          else if(data.c[i].type == 55) { msg = '<span class="time">['+data.c[i].time+']</span> '+genrank(data.c[i].nrank, data.c[i].prank)+' <span style="color: #00BB00">[Trade] <a href="javascript:m(\''+data.c[i].cname+'\');">'+data.c[i].cname+'</a>: '+data.c[i].message+'</span>'; }
          else if(data.c[i].type == 50) { msg = '<span class="time">['+data.c[i].time+']</span> <span style="color: #FF7171">Message Received: <a href="javascript:m(\''+data.c[i].cname+'\');">'+data.c[i].cname+'</a>: '+data.c[i].message+'</span>'; }
          else if(data.c[i].type == 51) { msg = '<span class="time">['+data.c[i].time+']</span> <span style="color: #F59292">Message Sent: <a href="javascript:m(\''+data.c[i].cname+'\');">'+data.c[i].cname+'</a>: '+data.c[i].message+'</span>'; }
          else if(data.c[i].type == 2) { msg = '<span class="time">['+data.c[i].time+']</span> '+genrank(data.c[i].nrank, data.c[i].prank)+' <i>* '+genStatus(data.c[i].status)+'<a href="javascript:m(\''+data.c[i].cname+'\');">'+data.c[i].cname+'</a> '+data.c[i].message+'</span></i>'; }
          else if(data.c[i].type == 99) { msg = '<span class="time">['+data.c[i].time+']</span> '+data.c[i].message; chat_table = 10; }
          else if(data.c[i].type == 101) { msg = '<span class="time">['+data.c[i].time+']</span> '+genrank(data.c[i].nrank, data.c[i].prank)+' '+genStatus(data.c[i].status)+'<a href="javascript:m(\''+data.c[i].cname+'\');">'+data.c[i].cname+'</a>: '+data.c[i].message+'</span>'; chat_table = 50; }
          if(chat_table == 10) {
            $('#chat_table10').prepend('<tr id=\"ct10_tr'+(chatid10)+'\"><td>'+msg+'</td></tr>');
            chatid10++;
            if(chatview != 10) { chatcount10++; $('#chatcount10').html(' ('+chatcount10+')'); }
            if(initiate == 0) { $('#ct10_tr'+(chatid10-chatsize)).remove(); }
          }
          else if(chat_table == 50) {
            $('#chat_table50').prepend('<tr id=\"ct50_tr'+(chatid50)+'\"><td>'+msg+'</td></tr>');
            chatid50++;
            if(initiate == 0) { $('#ct50_tr'+(chatid50-chatsize)).remove(); }
          }
          else {
            chatLine(msg);
            if(chatview != 1) { chatcount1++; $('#chatcount1').html(' ('+chatcount1+')'); }
            if(initiate == 0) { $('#ct1_tr'+(chatid1-chatsize)).remove(); }
          }
        }
        if(data.fl) {window.location = 'http://www.heroesrpg.com';}
      });
    }
    stopActivityTimer();
    clearTimeout(chattimer);
    if(chatinactivity < 20) {
      chatinactivity++;
      chattimer = setTimeout(function() {
        update_chat(0);
      }, 5000);
    } else {
      chattimer = setTimeout(function() {
        update_chat(0);
      }, 9000);
    }
  }, 'json');
}

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址