Greasy Fork

Greasy Fork is available in English.

HWM_BC_Last_Online

Последний онлайн персонажей в клане

当前为 2015-09-29 提交的版本,查看 最新版本

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name        HWM_BC_Last_Online
// @namespace   Рианти
// @description Последний онлайн персонажей в клане
// @include     http://www.heroeswm.ru/clan_info.php?id=*
// @version     1
// @grant       GM_xmlhttpRequest
// ==/UserScript==

try{
  addQuickLink ('Последний онлайн', 'last_online',
                function (){
                  work();
                  });
  
} catch(e){
  console.log(e);
}

function addQuickLink (label, id, action){
  var quickLinksTableTR = document.querySelector('body > center:nth-child(2) > table:nth-child(1) > tbody:nth-child(1) > tr:nth-child(1)');
  var td = document.createElement('td');
  td.innerHTML = '<div id="breadcrumbs" style="z-index: auto;"><ul style="z-index: auto;"><li class="subnav" style="z-index: auto;"><nobr>\
| <a class="pi" id="' + id + '" href="javascript:void(0)">' + label + '</a>\
</nobr></li></ul></div>';
  quickLinksTableTR.appendChild(td);
  var elem = document.getElementById(id);
  elem.onclick = action;
}

function work (){
  try{
  var p = document.querySelectorAll('a[href*="pl_info.php?id="]');
  var dataTable = p[p.length-1].parentElement.parentElement.parentElement;    
  var cells = dataTable.querySelectorAll("td"); //relevant cells are 3, 5 in each row
  var rows =cells.length/5;
  var tmp,plID,plNick,plLVL;

  for (var i = 0; i < rows; i++) {
    tmp = cells[i * 5 + 2].getElementsByClassName('pi')[0];
    plID = tmp.href.split('=')[1];
    try{
    cells[i * 5 + 4].innerHTML = getPageContent('http://www.heroeswm.ru/pl_info.php?id=' + plID).querySelector('td:nth-child(2) > i:nth-child(1)').innerHTML;
    } catch(e) { cells[i * 5 + 4].innerHTML = 'Онлайн' }
  }
  } catch (E) {console.log(E,getPageContent('http://www.heroeswm.ru/pl_info.php?id=' + plID).innerHTML)}
}

function getPageContent(url)
{
    try {
    console.log('loading: ', url);
    var xmlhttp = new XMLHttpRequest();
    xmlhttp.open('GET', url, false);
    xmlhttp.overrideMimeType('text/plain; charset=windows-1251');
    xmlhttp.send(null);
    if(xmlhttp.status == 200)
        return new DOMParser().parseFromString(xmlhttp.responseText, 'text/html').documentElement;
    return '';
    } catch ( e ) {
        return getPageContent(url);
    }
}