OGame-RaidsTable

Tableau de raids

Verze ze dne 16. 10. 2015. Zobrazit nejnovější verzi.

K instalaci tototo skriptu si budete muset nainstalovat rozšíření jako Tampermonkey, Greasemonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Userscripts.

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

K instalaci tohoto skriptu si budete muset nainstalovat manažer uživatelských skriptů.

(Už mám manažer uživatelských skriptů, nechte mě ho nainstalovat!)

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.

(Už mám manažer uživatelských stylů, nechte mě ho nainstalovat!)

// ==UserScript==
// @name        OGame-RaidsTable
// @description Tableau de raids
// @description:en Raids table
// @namespace   Xanatos
// @include     http://*.ogame.gameforge.com/game/index.php?page=messages
// @version     1.5.0
// @grant       none
// ==/UserScript==

// Compatibility OGame 6.0.6

(function()
{
	function numberWithCommas(x)
	{
		return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ".");
	}

	function removeElement(node)
	{
		node.parentNode.removeChild(node);
	}
	
	function convertOgameFormatToDigits(x)
	{
		var splitX = x.split('M');
		var resources = splitX[0].replace(/\,/g , '');
		resources = parseInt(resources);
		resources += 1;
		resources *= 1000;
		return resources;
	}
	
	function raidsTable_init()
	{
		if(document.querySelector('#chatBar'))
		{
			var uiid20_ul = document.querySelector("#ui-id-20 .tab_inner:first-child");
		}
		else
		{
			var uiid20_ul = document.querySelector("#ui-id-14 .tab_inner:first-child");
		}
		var raidsTable = document.querySelector("#raidsTable_container");
		
		// display table if not exist
		if (uiid20_ul && !raidsTable)
		{
			// get all messages
			var computed_messages = [];
			var raw_messages = uiid20_ul.querySelectorAll('li.msg'), i;
			for(i = 0; i < raw_messages.length; i++)
			{
				var current_raw_message = raw_messages[i];
				var computed_message_built = {};
				
				if(current_raw_message.querySelectorAll('.espionageDefText').length == 0)
				{
					// message id
					computed_message_built.id = current_raw_message.getAttribute('data-msg-id');
					
					// player and coordinates
					var player = current_raw_message.querySelectorAll('.msg_content')[0].querySelectorAll('div')[0];
					var player_html_nodes = player.children;
					var player_html = "", k = 0;
					for(k = 1; k < player_html_nodes.length; k++)
					{
						if(k > 1)
						{
							player_html += ' ';
						}
						player_html += player_html_nodes[k].innerHTML
					}
					computed_message_built.player = player_html;
					
					// booty percent
					var booty = current_raw_message.querySelectorAll('.msg_content')[0].querySelectorAll('div')[2].querySelectorAll('span')[0];
					booty = booty.innerHTML;
					var regex = /[\d\.]+/g;
					booty = booty.match(regex)[0];
					booty = parseInt(booty);
					computed_message_built.booty = booty;
					
					// resources booty
					var resources = current_raw_message.querySelectorAll('.msg_content')[0].querySelectorAll('div')[1].querySelectorAll('.fright')[0];
					resources = resources.innerHTML;
					console.log(resources);
					var regex = /[\d\.,M]+/g;
					resources = resources.match(regex)[0];
					if(resources.slice(-1) == 'M')
					{
						resources = convertOgameFormatToDigits(resources);
					}
					else
					{
						resources = resources.replace(/\./g , '');
					}
					resources = Math.round(resources * (computed_message_built.booty / 100));
					computed_message_built.raw_resources = resources;
					computed_message_built.resources = numberWithCommas(resources);
					
					// gt
					computed_message_built.gt = Math.round(computed_message_built.raw_resources/25000*1.1);
					
					// pt
					computed_message_built.pt = Math.round(computed_message_built.raw_resources/5000*1.1);
					
					// fleet
					var fleet = current_raw_message.querySelectorAll('.msg_content')[0].querySelectorAll('div')[3].querySelectorAll('span')[0].getAttribute('title');
					computed_message_built.fleet = fleet;

					// recycler
					recycler = computed_message_built.fleet.replace(/\./g , '');
					computed_message_built.recycler = Math.round(recycler/20000);
					
					// defense
					var defense = current_raw_message.querySelectorAll('.msg_content')[0].querySelectorAll('div')[3].querySelectorAll('span')[1].getAttribute('title');
					computed_message_built.defense = defense;
					
					// attack button
					var attack_button = current_raw_message.querySelectorAll('.msg_actions')[0].querySelectorAll('a')[2].getAttribute('href');
					computed_message_built.attack_button = attack_button;
					
					
					current_raw_message.style.border = '1px solid yellow';
					current_raw_message.setAttribute('id', 'anchor'+computed_message_built.id);
					computed_messages.push(computed_message_built);
				}
			}
			
			// construct table
			var table = '<table id="raidsTable" class="content_table">';
			table += '<tr class="ct_head_row">';
			table += '<th class="ct_th">#</th>';
			table += '<th class="ct_th">Joueur</th>';
			table += '<th class="ct_th">Flotte</th>';
			table += '<th class="ct_th">Défense</th>';
			table += '<th class="ct_th">Pillage</th>';
			table += '<th class="ct_th">GT</th>';
			table += '<th class="ct_th">PT</th>';
			table += '<th class="ct_th">R</th>';
			table += '<th class="ct_th"></th>';
			table += '<th class="ct_th"></th>';
			table += '</tr>';
					
			var j;
			for(j = 0; j < computed_messages.length; j++)
			{
				var tr_class = j%2 == 0 ? 'odd' : 'even';
				var tr_row = j+1;
				var current_computed_message = computed_messages[j];
				
				var attack = '<a href="'+current_computed_message.attack_button+'">';
				attack += '<span class="icon_nf icon_attack"></span>';
                attack += '</a>';
				
				var del_button = '<li class="msg" data-msg-id="' + current_computed_message.id + '">';
				del_button += '<a class="fright" onclick="this.parentNode.parentNode.parentNode.style.display=\'none\';document.querySelector(\'#anchor' + current_computed_message.id + '\').style.display=\'none\'" href="javascript:void(0);">'; // 
				del_button += '<span title="" class="icon_nf icon_refuse js_actionKill tooltip js_hideTipOnMobile"></span>';
				del_button += '</a></li>';
				
				table += '<tr class="' + tr_class + '" id="msg_'+current_computed_message.id+'" data-id="'+current_computed_message.id+'">';
				table += '<td class="ct_td"><a href="#anchor'+current_computed_message.id+'">#'+tr_row+'</a></td>';
				table += '<td class="ct_td">' + current_computed_message.player + '</td>';
				table += '<td class="ct_td">' + current_computed_message.fleet + '</td>';
				table += '<td class="ct_td">' + current_computed_message.defense + '</td>';
				table += '<td class="ct_td">' + current_computed_message.resources + ' <span style="font-size:9px">('+current_computed_message.booty+'%)</span></td>';
				table += '<td class="ct_td">' + current_computed_message.gt + '</td>';
				table += '<td class="ct_td">' + current_computed_message.pt + '</td>';
				table += '<td class="ct_td">' + current_computed_message.recycler + '</td>';
				table += '<td class="ct_td">'+attack+'</td>';
				table += '<td class="ct_td">'+del_button+'</td>';
				table += '</tr>';
			}
			
			table += '</table>';
			
			var containerElement = document.createElement("div"); // On crée un nouvelle élément div
			containerElement.innerHTML = table;
			containerElement.id ='raidsTable_container';
			//containerElement.style.border = '1px solid red';
			containerElement.style.clear = 'both';
			uiid20_ul.insertBefore(containerElement, uiid20_ul.firstChild);
		}
	}
	
	setInterval(raidsTable_init, 500);
})();