Add Agent to Search

Show agent on player search pages

Versione datata 09/10/2014. Vedi la nuova versione l'ultima versione.

Dovrai installare un'estensione come Tampermonkey, Greasemonkey o Violentmonkey per installare questo script.

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

Dovrai installare un'estensione come Tampermonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Userscripts per installare questo script.

Dovrai installare un'estensione come ad esempio Tampermonkey per installare questo script.

Dovrai installare un gestore di script utente per installare questo script.

(Ho già un gestore di script utente, lasciamelo installare!)

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

(Ho già un gestore di stile utente, lasciamelo installare!)

// ==UserScript==
// @name           Add Agent to Search
// @namespace      GLB
// @description    Show agent on player search pages
// @include        http://glb.warriorgeneral.com/game/search.pl* 
// @version 0.0.1.20141009121029
// ==/UserScript==
window.setTimeout(function ()
{
  function getElementsByClassName(classname, par)
  {
    var a = [
    ];
    var re = new RegExp('\\b' + classname + '\\b');
    var els = par.getElementsByTagName('*');
    for (var i = 0, j = els.length; i < j; i++)
    {
      if (re.test(els[i].className))
      {
        a.push(els[i]);
      }
    }
    return a;
  };
  var buseshort = true;
  var loaded = false;
  //create loadAgent link
  var loadLink = document.createElement('a');
  loadLink.setAttribute('href', '#');
  loadLink.innerHTML = 'Load Agent Names';
  loadLink.addEventListener('click', loadAgents, false);
  // subhead_link_bar
  var subhead_link_bar = getElementsByClassName('subhead_link_bar', document);
  subhead_link_bar[0].innerHTML = subhead_link_bar[0].innerHTML + ' | ';
  subhead_link_bar[0].appendChild(loadLink);
  function getAgentName(playerId, i)
  {
    GM_xmlhttpRequest({
      method: 'GET',
      url: 'http://glb.warriorgeneral.com/game/player.pl?player_id=' + playerId,
      headers: {
        'User-agent': 'Mozilla/4.0 (compatible) Greasemonkey',
        'Accept': 'application/atom+xml,application/xml,text/xml',
      },
      onload: function (agntname) {
        var response1 = agntname.responseText
        var agntname = response1.split('user_id=');
        var name1 = agntname[1].split('">');
        var agntID = name1[0];
        var name2 = name1[1].split('</');
        var container = document.getElementById('content')
        if (buseshort) {
          var playerbox = getElementsByClassName('player_name_short', document)
        } else {
          var playerbox = getElementsByClassName('search_name', document)
        }
        playerbox[i].innerHTML = playerbox[i].innerHTML + '<br><a href=\'/game/home.pl?user_id=' + agntID + '\' style=\'color:blue\'\'><span style=\'font: 10pt black bold;\'>' + name2[0] + '</span></a>';
      }
    });
  };
  function loadAgents() {
    if (!loaded) {
      loaded = true;
      var playernames = getElementsByClassName('player_name_short', document);
      if (playernames.length == 0) {
        buseshort = false;
        var playernames = getElementsByClassName('search_name', document);
      }
      for (var i = 0; i < playernames.length; i++) {
        var playerInfo = playernames[i].innerHTML;
        var idlong = playerInfo.split('player_id=');
        var id = idlong[1].split('">');
        getAgentName(id, i);
      }
    }
  };
}, 100);