﻿// ==UserScript==
// @name          UL專用OGAME屏蔽器
// @author 	  OgamerNL
// @description   去除所有OGAME廣告, 增加地質學家計算器, UL論壇連接和新的時間顯示方式.
// @include       http://uni8.ogame.tw/game/*.php*
// @exclude       http://uni8.ogame.tw/game/galaxy.php*
// @exclude       http://uni8.ogame.tw/game/stat.php*
// @exclude       http://uni8.ogame.tw/game/buddy.php*
// @exclude       http://uni8.ogame.tw/game/allianzen.php*
// ==/UserScript==

//戰鬥模擬器地址
var battlesims = 'redir.php?url=http://www.o-o-d.com/tool/sim/index.cgi?lang=en'


var findgeologiststext = "Find Geologists";
var findgeologistslocation = 'http://users.bigpond.net.au/hong/';
var findgeologistspage = 'fg';
var ultext = "U.L Forum";
var ullocation = 'http://unitedleague.forumable.net/forum/index.php?mforum=';
var ulpage = 'unitedleague';
var thispage=document.location.href;


//---------------------------------------------
(function() {	
	var Session = document.body.innerHTML.substr(document.body.innerHTML.indexOf("session=") + 8,12);
	var trs = document.getElementsByTagName('tr');
	
	for (var i = 0; i < trs.length; i++) {
		if(trs[i].innerHTML.indexOf("Info Comandante</font>") != -1){
			trs[i].parentNode.removeChild(trs[i]);			
		}
	}	

trs[trs.length-1].innerHTML ='<tr><td><img src="http://users.bigpond.net.au/hong/ulskin/gfx/info-help.jpg" height="19" width="110">'+
//聯盟論壇
'<div align="center""><font color="#FFFFFF"><a href="redir.php?url=http://203.95.2.114/index.php" target="_blank">'+ultext+'</a></font></div>'+
//戰鬥模擬器
//'<div align="center""><font color="#FFFFFF"><a href='+battlesims+' target="_blank">BattleSims</a></font></div>'+
//地質學者
'<div align="center"><font color="#FFFFFF"><a href="#" onclick="fenster(&#34;'+findgeologistslocation+findgeologistspage+'.html&#34;, &#34;'+findgeologistspage+'&#34;);">'+findgeologiststext+'</a></font></div>'+
//群組信息
'<div align="center"><font color="#FFFFFF"><a href="allianzen.php?session=' + Session + '&a=17"target="Hauptframe">Circular Message</a></font></div>'+
'<div align="center"><font color="#FFFFFF"><a href="redir.php?url=http://uni8.ogame.tw/game/index.php?session=' + Session + '" target="_blank">Convert Link</a></font></div>'+
//群組列表
//'<div align="center"><font color="#FFFFFF"><a href="allianzen.php?session=' + Session + '&a=4"target="Hauptframe">Member List</a></font></div>'+
//'<div align="center"><font color="#FFFFFF"><a href="allianzen.php?session=' + Session + '&a=4&sort1=3&sort2=0" target="Hauptframe">Member Ranking</a></font></div>'+
//群組管理
//'<div align="center"><font color="#FFFFFF"><a href="allianzen.php?session=' + Session + '&a=7" target="Hauptframe">Manage Members</a></font></div>'+
//'<div align="center"><font color="#FFFFFF"><a href="allianzen.php?session=' + Session + '&a=6" target="Hauptframe">Rights / Ranks</a></font></div>'+
//
'</td></tr>';
})();


function BuscarPos(array, id) {
   for(var i = 0; i < array.length; i++) {
      if(array[i] == id) return i;
	}
   return -1;
}


function AnoBisiesto(ano) {
   return (((ano % 4 == 0) && (ano % 100 != 0)) || (ano % 400 == 0)) ? 1 : 0;
}


function DiasMes(mes, ano) {
   if(mes == 0 || mes == 2 || mes == 4 || mes == 6 || mes == 7|| mes == 9 || mes == 11)
      return 31;
   if(mes == 3 || mes == 5 || mes == 8 || mes == 10)
      return 30;
   if(mes == 1 && AnoBisiesto(ano) == 0)
      return 28;
   else
      return 29;
}


function ClockNU() {
   nodeLocal = document.getElementById("ClockLocal");
   nodeServer = document.getElementById("ClockServer");
   nodeRefresh = document.getElementById("ClockRefresh");
   var date = new Date();
   var ano = date.getFullYear();
   var mes = date.getMonth();
   var dia = date.getDay();
   var diaNum = date.getDate();
   var hora = date.getHours();
   var mins = date.getMinutes();
   var segs = date.getSeconds();
   var dias = new Array('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday');
   var meses = new Array('January','February','March','April','May','June','July','August','September','October','November','December');
   var fecha = nodeServer.innerHTML.match(/(\S+) (\d+) (\S+) - (\d{2}):(\d{2}):(\d{2})/);
   nodeLocal.innerHTML = dias[dia] + ' ' + diaNum + ' ' + meses[mes] + ' - ' + ((hora < 10) ? '0' : '') + hora + ((mins < 10) ? ':0' : ':') + mins + ((segs < 10) ? ':0' : ':') + segs;
   dia = BuscarPos(dias, fecha[1]);
   diaNum = fecha[2] * 1;
   mes = BuscarPos(meses, fecha[3]);
   hora = fecha[4] * 1;
   mins = fecha[5] * 1;
   segs = fecha[6] * 1;
   if(++segs > 59) {
      segs = 0;
      if(++mins > 59) {
         mins = 0;
         if(++hora == 23) {
            hora = 0;
            if(++dia > 6) dia = 0;
            diaNum++;
            if(diaNum > DiasMes(mes, ano)) {
               diaNum = 1;
               if(++mes > 11) mes = 0;
            }
         }
      }
   }
   nodeServer.innerHTML = dias[dia] + ' ' + diaNum + ' ' + meses[mes] + ' - ' + ((hora < 10) ? '0' : '') + hora + ((mins < 10) ? ':0' : ':') + mins + ((segs < 10) ? ':0' : ':') + segs;
   var contador = nodeRefresh.innerHTML.match(/(\d{2}):(\d{2})/);
   mins = contador[1] * 1;
   segs = contador[2] * 1;
   if(--segs < 0 ) {
      segs = 59;
      if(--mins < 0){
         mins = 0;
         location.reload(true);
      }
   }
   nodeRefresh.innerHTML = ((mins < 10) ? '0' : '') + mins + ((segs < 10) ? ':0' : ':') + segs;
   if(document.baseURI.indexOf("overview.php") != -1)
      setTimeout(ClockNU, 1000);
}

if(document.baseURI.indexOf("overview.php") != -1) {

   var nodo = document.evaluate("/html/body/center/table[last()]/tbody/tr[th[2]]/th[2]", document, null, XPathResult.FIRST_ORDERED_NODE_TYPE,null).singleNodeValue;
   var dias = new Array('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday');
   var meses = new Array('January','February','March','April','May','June','July','August','September','October','November','December');
   var days = new Array('Sun','Mon','Tue','Wed','Thu','Fri','Sat');
   var months = new Array('Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec');

   var date = new Date();
   var mes = date.getMonth();
   var dia = date.getDay();
   var diaNum = date.getDate();
   var hora = date.getHours();
   var mins = date.getMinutes();
   var segs = date.getSeconds();

   var fecha = nodo.innerHTML.match(/(\S\S\S) (\S\S\S) (\d+) (\d+)(:\d\d:\d\d)/);
   var fechaLocal = dias[dia] + " " + diaNum + " " + meses[mes] + " - " + ((hora < 10) ? "0" : "") + hora + ((mins < 10) ? ":0" : ":") + mins + ((segs < 10) ? ":0" : ":") + segs;
   var fechaServer = dias[BuscarPos(days,fecha[1])] + " " + fecha[3] + " " + meses[BuscarPos(months, fecha[2])] + " - " + ((fecha[4] < 10) ? "0" : "") + fecha[4] + fecha[5];

   var nodoRefresh = nodo.parentNode.cloneNode(true);
   nodo.parentNode.parentNode.insertBefore(nodoRefresh, nodo.parentNode.nextSibling);
   var segsAleatoreo = Math.round(Math.random()*58)+1;
   var minsAleatoreo = Math.round(Math.random()*39)+20;
   nodoRefresh.innerHTML = "<th>Refresh</th><th colspan='3' id='ClockRefresh'>" + ((minsAleatoreo < 10) ? "0" : "") +  minsAleatoreo + ":" + ((segsAleatoreo < 10) ? "0" : "") + segsAleatoreo + "</th>";
   var nodoLocal = nodo.parentNode.cloneNode(true);
   nodo.parentNode.parentNode.insertBefore(nodoLocal, nodo.parentNode.nextSibling);
   nodoLocal.innerHTML = "<th>Local Time</th><th colspan='3' id='ClockLocal'>" + fechaLocal + "</th>";

   nodo.previousSibling.previousSibling.innerHTML='Server Time';
   nodo.innerHTML = fechaServer;
   nodo.setAttribute('id', 'ClockServer');
   setTimeout(ClockNU, 1000);
}
