// ==UserScript==
// @name           Pardus Gameserver Stats
// @namespace      pardus.at
// @description    shows stats for a selected game on the pardus gameserver
// @include        http://*.pardus.at/msgframe.php*
// ==/UserScript==
//by Spoilerhead (Orion) 2008
//Ver. 0.2

/* 
0.1: Initial Version
0.2: changed colors to use the same as the server

*/


var q_server ="Tremulous";   //set the game to monitor here (as shown on the gameserver stats page e.g. "Tremulous" or "Alien Arena 2008 Capture the Flag")


//--------------------------------------------------------------------------------------------------------

function setText(text) {
  //find the place to put the text
  var msg_Table= document.getElementsByTagName('table')[0];
  var msg_field = msg_Table.lastChild.lastChild.lastChild;
  msg_field.innerHTML += text;
}

function colorize(cur_players,max_players) {
  //calculate color 
  var cp =  parseInt(cur_players);
  var mp =  parseInt(max_players);
  var color = '#00FF00'; //green
  switch(cp) {
    case 0: color = "#FF0000"; break;
    case 1: color = "#FF6600"; break;
    case 2: color = "#FFAA00"; break;
    case 3: color = "#FFFF00"; break;
    case 4: color = "#aaFF00"; break;
    case 5: color = "#66FF00"; break;
  }

  return '<span style="color:'+color+';">'+cur_players+'/'+max_players+'</span>';
}

function parseStatus(status) {
  var tokens = status.responseText.split(';');
  setText('<div style="font-family: Verdana, Arial; color: #B0B0B0; font-size: 10px;text-align: right;">'
         +'<a href="http://gameserver.pardus.at" target="main" title="Current Map: '+tokens[2]+'">'
         +q_server+': '+ colorize(tokens[0],tokens[1])
         +'</a>'+'</div>'
         );
}


GM_xmlhttpRequest({
    method: 'GET',
    url: 'http://gameserver.pardus.at/stats.php?query='+q_server,
    headers: {
        'User-agent': 'Mozilla/4.0 (compatible) Greasemonkey',
        'Accept': 'application/atom+xml,application/xml,text/xml',
    },
    onload: function(responseDetails) {parseStatus(responseDetails);}
  });


