// ==UserScript==
// @name           eSuomen tiedotus
// @namespace      www.erepublik.com
// @description    eSuomen tiedotus
// @include        http://www.erepublik.com/en
// @include        http://www.erepublik.com/en/wars/1
// ==/UserScript==

var timestamp=new Date()
tiedote_url="http://www.erepublik.fi/tiedote.txt";
tiedote_url_cachebust=tiedote_url+"?r="+timestamp.getTime();
sota_url="http://www.erepublik.fi/sotamahd.txt";
sota_url_cachebust=sota_url+"?r="+timestamp.getTime();

box1_el = document.createElement("div")
						box1_el.setAttribute("style","background: #e9f5fa; padding: 12px; clear:both; margin-bottom:10px;");
						
	GM_xmlhttpRequest({
	method: 'GET',
        url: sota_url_cachebust,

	onload:function(responseDetails){

			var responseText = responseDetails.responseText;
			var tags = responseText.split('|');
			var text = tags[0];
			var link = tags[1]
			
			

			wars=document.getElementById('filters')

			text_el = document.createElement("h2")
						text_el.setAttribute("style","color: #2b7793; font-weight:bold;font-size:14px;");
			text_el.textContent=text
			box1_el.appendChild(text_el); 

			link_el = document.createElement("a"); 
			link_el.setAttribute('href',link)
                        link_el.setAttribute('style','float:left;')
                        link_el.setAttribute('style','clear:left;')
			link_el.innerHTML = link
			box1_el.appendChild(link_el); 

                        hr_el=document.createElement("hr")
                        hr_el.setAttribute('width','50%')
		
		}	
		}
	);


latest=document.getElementById('latestnews');
attention_el = document.createElement("h1");
attention_el.textContent="eSuomi tiedottaa:";
attention_el.setAttribute("style","margin-bottom:5px; width:100%;");
box1_el.appendChild(attention_el); 

GM_xmlhttpRequest({
	method: 'GET',
	url: tiedote_url_cachebust,

	onload:function(responseDetails){

			var responseText = responseDetails.responseText;
			var tags = responseText.split('|');
			var text1 = tags[0];
			var link1 = tags[1];
			var text2 = tags[2];
			var link2 = tags[3]

			
			text1_el = document.createElement("h2")
					text1_el.setAttribute("style","color: #2b7793; font-weight:bold;font-size:14px; margin-top:10px;");
			text1_el.textContent= text1
			box1_el.appendChild(text1_el); 
			

			link1_el = document.createElement("a"); 
			link1_el.setAttribute('href',link1)
                        link1_el.setAttribute('style','float:left;')
                        link1_el.setAttribute('style','clear:left;')
			link1_el.innerHTML = link1
			box1_el.appendChild(link1_el); 

			latest.parentNode.insertBefore(box1_el, latest)


			
			}	
		}
	);

	GM_xmlhttpRequest({
	method: 'GET',
	url: sota_url_cachebust,

	onload:function(responseDetails){

			var responseText = responseDetails.responseText;
			var tags = responseText.split('|');
			var text = tags[0];
			var link = tags[1]

			latest_war=document.getElementById('latestnews')

			text_el = document.createElement("h2")
                        text_el.setAttribute('style','float:left;')
                        text_el.setAttribute('style','clear:left;')
			text_el.textContent=text

			link_el = document.createElement("a"); 
			link_el.setAttribute('href',link)
                        link_el.setAttribute('style','float:left;')
                        link_el.setAttribute('style','clear:left;')
			link_el.innerHTML = link

                        hr_el=document.createElement("hr")
                        hr_el.setAttribute('width','50%')
			
              
		}	
		}
	);
