HWM_Monster_Links

Добавляет ссылки на описания монстров (Групповые бои/Помощь в охоте). Сначала нужно открыть страницу Рейтинг охотников (/plstats_hunters.php) для обновления ссылок.

目前為 2015-03-29 提交的版本,檢視 最新版本

// ==UserScript==
// @name HWM_Monster_Links
// @description Добавляет ссылки на описания монстров (Групповые бои/Помощь в охоте). Сначала нужно открыть страницу Рейтинг охотников (/plstats_hunters.php) для обновления ссылок.
// @namespace   MonsterLinks
// @author  Zeleax
// @include http://www.heroeswm.ru/plstats_hunters.php
// @include http://www.heroeswm.ru/group_wars.php*
// @include http://178.248.235.15/plstats_hunters.php
// @include http://178.248.235.15/group_wars.php*
// @include http://www.lordswm.com/plstats_hunters.php
// @include http://www.lordswm.com/group_wars.php*
// @grant   none
// @version 1.0
// ==/UserScript==
if (!this.GM_getValue || (this.GM_getValue.toString && this.GM_getValue.toString().indexOf("not supported")>-1)) {
    this.GM_getValue=function (key,def) {
        return localStorage[key] || def;
    };
    this.GM_setValue=function (key,value) {
        return localStorage[key]=value;
    };
    this.GM_deleteValue=function (key) {
        return delete localStorage[key];
    };
}

if(/plstats_hunters.php/.test(location.href)){
   var monsterarr = new Object();
   var ratetable =  getElementByXpath("/html/body/center/table[2]/tbody/tr/td/table/tbody/tr[5]/td/table");

   var rows=ratetable.getElementsByClassName("pi");
   for(var i=0; i<rows.length; i++)
   {
      el = rows[i];
      if ((href = el.getAttribute("href"))!=null && (res = /army_info.php\?name=(\S+)/.exec(href))!= null && res[1] != null)
         monsterarr[el.innerHTML] = res[1];
   }
   if (monsterarr != null) GM_setValue("monsters", JSON.stringify(monsterarr));
}
else if(/group_wars.php/.test(location.href))
{
   monsterarr = JSON.parse( GM_getValue("monsters", "none") );
   var battletable = getElementByXpath("/html/body/center/table[2]/tbody/tr/td/table/tbody/tr/td/table");
   var rows = battletable.rows;
   for(var i=0; i<rows.length; i++)
   {
      el = rows[i];
      var txt = el.cells[el.cells.length-1].innerHTML;
      if( (res = / vs .+>(.+)\(\d+\)/.exec(txt)) !=null && (monstername = res[1]) != null && (link = monsterarr[monstername])!=null)
            el.cells[el.cells.length-1].innerHTML = txt.replace(monstername,'<a href="army_info.php\?name='+link+'">'+monstername+'</a>');;
   }   
}

function getElementByXpath (path) {
  return document.evaluate(path, document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
}