OGame RaidsTable

Tableau de raids

As of 16. 10. 2015. See the latest version.

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 or Violentmonkey 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        OGame RaidsTable
// @description Tableau de raids
// @description:en Raids table
// @namespace   Xanatos
// @include     http://*.ogame.gameforge.com/game/index.php?page=messages
// @version     1.1.0
// @grant       none
// ==/UserScript==

(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 = {};
				
				// 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];
				removeElement(player.querySelectorAll('span')[0]);
				computed_message_built.player = player.innerHTML;
				
				// 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);
				
				// pt
				computed_message_built.pt = Math.round(computed_message_built.raw_resources/5000);
				
				// fleet
				var fleet = current_raw_message.querySelectorAll('.msg_content')[0].querySelectorAll('div')[3].querySelectorAll('span')[0].getAttribute('title');
				computed_message_built.fleet = fleet;
				
				// 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">Def</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"></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+'">Go</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">('+computed_message_built.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">'+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);
})();