// ==UserScript==
// @name           My City messenger
// @namespace      http://urosevic.net/greasemonkey
// @description    Compose predefined or custom bulletin message on visit to minicity.in city
// @include        http://*minicity.in/index.php?city=*
// @exclude        http://*minicity.in/index.php?city=alexandria
// ==/UserScript==

/*
Author: Aleksandar Urošević, urke@users.sourceforge.net
License: GNU GPLv3
Version: 0.4
ChangeLog:
	* 0.4 (24.05.2008): added resource and city info (city name, state, bank and population) + first public release
	* 0.3 (20.05.2008): added message for HYDRA i Yarold
	* 0.2 (19.05.2008): added popup menu with basic predefined text options and custom text
	* 0.1 (18.05.2008): initial release, static text without interactive change
*/

function mycitymsg()
{
	var mcm_mode = GM_getValue("mcm_mode", "standard");
	var mcm_sig = GM_getValue("mcm_sig", "Aleksandar, mayor of city Alexandria");
	
	switch (mcm_mode)
	{
	case "friends":
		mcm_text = "Mission: Friendly cities visit wave.\nAcomplished by: " + mcm_sig + " :D";
		break;
	case "top100":
		mcm_text = "Mission: TOP100 cities visit wave.\nYour current state: " + mcm_resursi() +"\nDone by: " + mcm_sig + " :)";
		break;
	case "new":
		mcm_text = "Mission: New cities visit wave.\nDone by: " + mcm_sig + " :)";
		break;
	case "squad":
		mcm_text = "Mission: CMC Forum Click Squad visit wave.\nAcomplished by: " + mcm_sig + " :)";
		break;
	case "hydra":
		mcm_text = "Mission: Hydra System visit wave.\nAcomplished by: " + mcm_sig + " :)";
		break;
	case "yarold":
		mcm_text = "Mission: Yarold's SWLE visit wave.\nAcomplished by: " + mcm_sig + " :)";
		break;
	case "custom":
		mcm_text = GM_getValue("mcm_custom", "I bring new resider to your city. Visit me back :)");
		break;
	default: // standard
		mcm_text = "Your city " + mcm_info() + " has visited by " + mcm_sig + ". Your city now have " + mcm_resursi() + "\n\nBe my guest and visit me back :D";
	}
	
	document.getElementById('data5').innerHTML = mcm_text;
	document.location = document.location + "#commentEditor";
}

function mcm_setcustom()
{
	var tmp = GM_getValue("mcm_custom", "I bring new resider to your city. Visit me back :)");
	tmp = prompt("Please enter your custom text, or change old.", tmp);
	GM_setValue("mcm_custom", tmp);
	GM_setValue("mcm_mode", "custom");
	mycitymsg();
}

function mcm_setsignature()
{
	var tmp = GM_getValue("mcm_sig", "Aleksandar, mayor of city Alexandria");
	tmp = prompt("Please enter your new signature text, or change old.", tmp);
	GM_setValue("mcm_sig", tmp);
	mycitymsg();
	
}

function mcm_resursi()
{
	var cinfo = document.getElementById('cityInfo').getElementsByTagName('li');
 	var banka = cinfo[0].getElementsByTagName('span')[0].innerHTML.replace(/(\t|\n|€)/g, "");
	var populacija = cinfo[5].getElementsByTagName('span')[0].innerHTML.replace(/(\t|\n)/g, "");
	return banka + " € in bank and " + populacija + " residers.";
}

function mcm_info()
{
	var pinfo = document.getElementById('placeInfo');
	var city = pinfo.getElementsByTagName('h2')[0].innerHTML.split(": ")[1].replace(/\t/g, "");
	var state = pinfo.getElementsByTagName('h3')[0].innerHTML.split(": ")[1].replace(/\t/g, "");
	var rank = document.getElementById('rank').getElementsByTagName('strong')[0].innerHTML;
	return city + " from " + state + " (curently on place #" + rank + ")";
}

GM_registerMenuCommand( "Standard", function() { GM_setValue("mcm_mode", "standard"); mycitymsg(); } );
GM_registerMenuCommand( "Friends", function() { GM_setValue("mcm_mode", "friends"); mycitymsg(); } );
GM_registerMenuCommand( "TOP100", function() { GM_setValue("mcm_mode", "top100"); mycitymsg(); } );
GM_registerMenuCommand( "New cities", function() { GM_setValue("mcm_mode", "new"); mycitymsg(); } );
GM_registerMenuCommand( "CMC Squad", function() { GM_setValue("mcm_mode", "squad"); mycitymsg(); } );
GM_registerMenuCommand( "Hydra", function() { GM_setValue("mcm_mode", "hydra"); mycitymsg(); } );
GM_registerMenuCommand( "Yarold's SWLE", function() { GM_setValue("mcm_mode", "yarold"); mycitymsg(); } );
GM_registerMenuCommand( "Custom", function() { GM_setValue("mcm_mode", "custom"); mycitymsg(); } );
GM_registerMenuCommand( "Set signature", function() { mcm_setsignature(); } );
GM_registerMenuCommand( "Set custom message", function() { mcm_setcustom(); } );

mycitymsg();
