DotD tools

Tools for DotD on Kongregate

Pada tanggal 03 Agustus 2014. Lihat %(latest_version_link).

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

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

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

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

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

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name        DotD tools
// @namespace   http://www.flipmctwist.tk
// @description Tools for DotD on Kongregate
// @include     http://www.kongregate.com/games/*
// @version     1.0
// @grant       GM_xmlhttpRequest
// @grant       GM_getValue
// @grant       GM_setValue
// ==/UserScript==

function main(s) {
	var dotd_tools = s;
	window.load = function(n) {
		if (typeof holodeck == 'object' && holodeck.ready == true) {
			init();
		}
		else if (n < 25) {
			setTimeout(function(){load(n+1);},1000);
		}
		else { console.log('DE: aborting'); }
	}
	load(0);
	
	window.init = function() {
		ChatDialogue.MESSAGE_TEMPLATE=new Template('<p class="#{classNames}"><span class="#{userClassNames} username time">#{time}</span> <span username="#{username}" class="username #{userClassNames}" oncontextmenu="rWhisper(\'#{username}\');return false;">#{prefix}#{username}</span><span class="separator">: </span><span class="message hyphenate">#{message}</span><span class="clear"></span></p>');
		ChatDialogue.MESSAGE_TEMPLATE.reEval = ChatDialogue.MESSAGE_TEMPLATE.evaluate;
		ChatDialogue.MESSAGE_TEMPLATE.evaluate = function(a) {
			a.time = dotd_tools['tools_timestamp'] == true ? timestamp() + "&nbsp;": "";
			return this.reEval(a);
		};
		
		ChatDialogue.prototype.msgHandler = ChatDialogue.prototype.displayUnsanitizedMessage;
		ChatDialogue.prototype.displayUnsanitizedMessage = function(a,b,c,d) {
			//console.log("Chat:" + a,b);
			if (!c) { c = {}; }
			if (dotd_tools['tools_charter'] == true && /kv_action_type\=signcharter/.test(b)) { return; }
			if (dotd_tools['tools_friend'] == true && isFriend(a)) { c.class += " friend"; }
			if (dotd_tools['tools_highlight'] == true) { 		
				if (b.search(holodeck._username) >= 0) {
					c.class += " highlight"; 
				}
				else { 
					var s = dotd_tools['tools_highlight_list'];
					var r = new RegExp("(^|\\s)("+s.replace(/,/g,'|')+")(\\s|$)", "i");
					if (r.test(b)) { c.class += " highlight"; }
				}
			}
			this.msgHandler(a,b,c,d);
		};
		newTab();
		setCSS();
		holodeck.addChatCommand("room",function(o,t) {
			var n;
			if (n = /^\/room\s(\d{1,2})/.exec(t)) {
				changeRoom(n[1]);
				return false;
			}
		});
		holodeck.addChatCommand("echo",function(o,t) {
			var n;
			if (n = /^\/echo\s(.+?)$/.exec(t)) {
				echo(n[1]);
				return false;
			}
		});
		holodeck.addChatCommand("share",function(o,t) {
			var n;
			if (n = /^\/share\s(.+?)$/.exec(t)) {
				if (/kv_action_type\=raidhelp/.test(t)) {
					shareMsg(n[1]);
					return false;
				}
				else {
					echo("Not a valid raid link");
					return false;
				}
			}
		});
		holodeck.addChatCommand("tools",function(o,t) {
			msgRoom("DotD tools by DanElectro: https://greasyfork.org/scripts/3827-dotd-tools");
			return false;
		});
	}
	window.msgRoom = function(msg) {
		holodeck.activeDialogue()._holodeck.filterOutgoingMessage(msg,holodeck.activeDialogue()._onInputFunction);
	}
	window.echo = function(msg) {
		holodeck.activeDialogue().msgHandler("DotD Tools:",msg,{class: "whisper whisper_received"},{non_user: true});
	}
	window.shareMsg = function(msg) {
		var x = document.getElementById('tools_share_table');
		for (var i=0;x.children[i];i++) {
			holodeck.activeDialogue().sendPrivateMessage(x.children[i].id,msg);
		}
	}
	window.newTab = function(name) {
		var pane = document.createElement('div');
		var link = document.createElement('a');
		var tab = document.createElement('li');
		var html = [
			'<div id="tools_cont" style="height:'+document.getElementById('chat_tab_pane').style.height+';">',
				'<div>DotD tools by DanElectro</div><br />',
				'<form id="tools_settings" class="tools_form" onSubmit="saveData();return false;">',
					'<input type="checkbox" name="tools_timestamp" /> Enable timestamp<br />',
					'<input type="checkbox" name="tools_charter" /> Hide guild charter messages<br />',
					'<input type="checkbox" name="tools_friend" /> Friend color: <input type="text" name="tools_fcolor" class="iSmall" /><br />',
					'<input type="checkbox" name="tools_highlight" /> Highlight color: <input type="text" name="tools_hcolor" class="iSmall" /><br />',
					'<input type="checkbox" name="tools_highlight_ext" /> Also Highlight: <input type="text" name="tools_highlight_list" /><br />',
					'<input type="submit" value="Save"> <span id="tools_save_info"></span>',
				'</form>',
				'<br /><hr /><br /><div>Raid sharing</div><br />',
				'<form id="tools_sharing" class="tools_form" onSubmit="addShare();return false;">',
					'<div id="tools_share_table"></div><br />',
					'<input type="text" name="tools_share_name" id="tools_share_name" class="iSmall" /> <input type="submit" value="Add" /><br />',
				'</form>',
				'<br /><hr /><br /><div>Chat Commands</div><br />',
				'<form id="tools_commands" class="tools_form" onSubmit="addCmd();return false;">',
					'<div id="tools_com_table"></div><br />',
					'Command: <br/><input type="text" name="tools_cmdname" id="tools_cmdname" class="iSmall" /><br />',
					'Message: <br /><input type="text" name="tools_cmddata" id="tools_cmddata" class="iBig" /><br /><br />',
					'<input type="submit" value="New" />',
				'</form>',
			'</div>'
		].join('');
		pane.setAttribute('id','tools_tab_pane');
		pane.setAttribute('class','tabpane');
		pane.setAttribute('style','display:none;');
		pane.innerHTML = html;
		link.setAttribute('href','#tools_tab_pane');
		link.innerHTML = 'Tools';
		tab.setAttribute('id','tools_tab');
		tab.setAttribute('class','tab');
		tab.appendChild(link);
		document.getElementById('kong_game_ui').appendChild(pane);
		document.getElementById('main_tab_set').appendChild(tab);
		holodeck._tabs.addTab(link);
		loadData();
	}
	window.setCSS =  function() {
		document.getElementById("tools_css").innerHTML = [
			'.time {float:left!important;}',
			'.iBig {width:98%;}',
			'.iSmall {width:60px;}',
			'.friend span.username {color:'+ dotd_tools["tools_fcolor"] +'!important;}',
			'.highlight .message {color:'+ dotd_tools["tools_hcolor"] +'!important;}',
			'.tools_share_name {border: 1px solid #666666; padding:1px;}',
			'.cmdname {width:50px;display:inline-block;}',
			'#tools_com_table {overflow-x:auto;white-space:nowrap;}'
		].join('');
	}
	window.addCmd = function() {
		var cname = document.getElementById('tools_cmdname');
		var cdata = document.getElementById('tools_cmddata');
		if (cname.value && cdata.value) {
			var cn = cname.value.replace(/\//,"")
			document.getElementById('tools_com_table').innerHTML += '<div class="tools_cmd" id="'+cn+'"><span><sup><a href="#" onClick="remCmd(this);return false;">[remove]</a></sup></span> <span class="cmdname">/'+cn+'</span> <span>:</span> <span class="cmditem">'+cdata.value+'</span></div>';
			window.postMessage('DotD_tools addcom '+cn+'|'+cdata.value,'*');
			regCmd(cn,cdata.value);
			cname.value = "";
			cdata.value = "";
		}
	}
	window.remCmd = function(x) {
		var e = x.parentElement.parentElement.parentElement;
		e.parentElement.removeChild(e);
		window.postMessage('DotD_tools remcom '+e.id,'*')
	}
	window.regCmd = function(name,msg) {
		holodeck.addChatCommand(name, function(o,t) {
			msgRoom(msg);
			return false;
		});
	}
	window.addShare =  function() {
		var n = document.getElementById('tools_share_name').value;
		if (n) {
			document.getElementById('tools_share_name').value = "";
			document.getElementById('tools_share_table').innerHTML += '<span class="tools_share_name" id="'+n+'">'+n+'<sup><a href="#" onClick="remShare(this);return false;">x</a></sup></span> ';
			window.postMessage('DotD_tools make share','*');
		}
	}
	window.remShare = function(x) { 
		var e = x.parentElement.parentElement;
		e.parentElement.removeChild(e);
		window.postMessage('DotD_tools make share','*');
	}
	window.saveData = function() {
		var x = document.getElementById('tools_settings');
		var sdata = {};
		var d = new Date();
		for (var i=0;i < x.length;i++) {
			if (x.elements[i].type == "checkbox") { sdata[x.elements[i].name] = x.elements[i].checked; }
			else if (x.elements[i].type == "text") { 
				var val = x.elements[i].value;
				sdata[x.elements[i].name] = val.replace(/(\'|\"|;|\(|\)|\{|\})/,"");
			}
		}
		dotd_tools = sdata;
		setCSS();
		window.postMessage('DotD_tools save '+JSON.stringify(sdata),'*');
		document.getElementById("tools_save_info").innerHTML = "Saved at "+ d.toLocaleTimeString();
	}
	window.loadData = function() {
		window.postMessage('DotD_tools load','*');
	}
	window.rWhisper = function(name) {
		holodeck.chatWindow().insertPrivateMessagePrefixFor(name);
	}
	window.isFriend = function(name) {
		return holodeck.activeDialogue()._user_manager.isFriend(name);
	}
	window.timestamp = function() {
		var d = new Date();
		var h = (d.getHours() < 10) ? "0"+d.getHours() : d.getHours();
		var m = (d.getMinutes() < 10) ? "0"+d.getMinutes() : d.getMinutes();
		return '['+h+':'+m+']';
	}
	window.changeRoom = function(n) { 
		n=n-1;
		if (n >= 0 && n < 13) {
			var r = [
				{"name":"Dawn of the Dragons - Room #01","id":"44247","xmpp_name":"138636-dawn-of-the-dragons-1","type":"game"},
				{"name":"Dawn of the Dragons - Room #02","id":"138636","xmpp_name":"138636-dawn-of-the-dragons-2","type":"game"},
				{"name":"Dawn of the Dragons - Room #03","id":"44303","xmpp_name":"138636-dawn-of-the-dragons-3","type":"game"},
				{"name":"Dawn of the Dragons - Room #04","id":"44336","xmpp_name":"138636-dawn-of-the-dragons-4","type":"game"},
				{"name":"Dawn of the Dragons - Room #05","id":"44341","xmpp_name":"138636-dawn-of-the-dragons-5","type":"game"},
				{"name":"Dawn of the Dragons - Room #06","id":"44345","xmpp_name":"138636-dawn-of-the-dragons-6","type":"game"},
				{"name":"Dawn of the Dragons - Room #07","id":"44348","xmpp_name":"138636-dawn-of-the-dragons-7","type":"game"},
				{"name":"Dawn of the Dragons - Room #08","id":"44464","xmpp_name":"138636-dawn-of-the-dragons-8","type":"game"},
				{"name":"Dawn of the Dragons - Room #09","id":"44465","xmpp_name":"138636-dawn-of-the-dragons-9","type":"game"},
				{"name":"Dawn of the Dragons - Room #10","id":"44466","xmpp_name":"138636-dawn-of-the-dragons-10","type":"game"},
				{"name":"Dawn of the Dragons - Room #11","id":"44467","xmpp_name":"138636-dawn-of-the-dragons-11","type":"game"},
				{"name":"Dawn of the Dragons - Room #12","id":"44468","xmpp_name":"138636-dawn-of-the-dragons-12","type":"game"},
				{"name":"Dawn of the Dragons - Room #13","id":"44473","xmpp_name":"138636-dawn-of-the-dragons-13","type":"game"}
			]
			holodeck.joinRoom(r[n]);
		}
	}
}
function rMessage(e) {
	var r;
	if (r = /^DotD_tools\ssave\s(.+?)$/.exec(e.data)) { 
		GM_setValue("settings",r[1]);
	}
	else if (r = /^DotD_tools\sload$/.exec(e.data)) { 
		var sdata = JSON.parse(GM_getValue("settings"));
		var x = document.getElementById('tools_settings');
		for (var i=0;x.elements[i] != null;i++) {
			if (x.elements[i].type == "checkbox") { x.elements[i].checked = sdata[x.elements[i].name]; }
			else if (x.elements[i].type == "text") { x.elements[i].value = sdata[x.elements[i].name]; }
		}
		sdata = JSON.parse(GM_getValue("share"));
		var html = "";
		for (var i=0;sdata[i] != null;i++) {
			html += '<span class="tools_share_name" id="'+sdata[i]+'">'+sdata[i]+'<sup><a href="#" onClick="remShare(this);return false;">x</a></sup></span> ';
		}
		document.getElementById('tools_share_table').innerHTML = html;
		html = "";
		sdata = JSON.parse(GM_getValue("commands"));
		for (var i in sdata) {
			html += '<div class="tools_cmd" id="'+i+'"><span><sup><a href="#" onClick="remCmd(this);return false;">[remove]</a></sup></span> <span class="cmdname">/'+i+'</span> <span>:</span> <span class="cmditem">'+sdata[i]+'</span></div>';
			unsafeWindow.regCmd(i,sdata[i]);
		}
		document.getElementById('tools_com_table').innerHTML = html;
	}
	else if (r = /^DotD_tools\smake\sshare$/.exec(e.data)) {
		var sdata = {};
		var x = document.getElementById('tools_share_table');
		for (var i=0;x.children[i];i++) {
			sdata[i] = x.children[i].id;
		}
		GM_setValue("share",JSON.stringify(sdata));
	}
	else if (r = /^DotD_tools\saddcom\s(.+?)$/.exec(e.data)) {
		var sdata = GM_getValue("commands") ? JSON.parse(GM_getValue("commands")) : {};
		var x = r[1].split("|");
		sdata[x[0]] = x[1];
		GM_setValue("commands",JSON.stringify(sdata));
	}
	else if (r = /^DotD_tools\sremcom\s(.+?)$/.exec(e.data)) {
		var sdata = JSON.parse(GM_getValue("commands"));
		delete sdata[r[1]];
		GM_setValue("commands",JSON.stringify(sdata))
	}
}
if (window.top == window.self) {
	if (GM_getValue("settings") == undefined) { 
		var s = {"tools_timestamp":true,"tools_charter":false,"tools_friend":false,"tools_fcolor":"#0088CC","tools_highlight":false,"tools_hcolor":"#00CCCC","tools_highlight_ext":false,"tools_highlight_list":""};
		GM_setValue("settings",JSON.stringify(s));
		GM_setValue("share","");
		GM_setValue("commands","");
	}
	var s = GM_getValue("settings");
	var script = document.createElement('script'); 
	script.type = "text/javascript"; 
	script.appendChild(document.createTextNode('('+main+')('+s+')'));
	document.head.appendChild(script);
	window.addEventListener("message",rMessage,false);
	var css = document.createElement('style');
	css.setAttribute('id','tools_css');
	css.type = "text/css";
	document.head.appendChild(css);
}