InfoPerk

Perk table -> homepage

目前為 2019-02-26 提交的版本,檢視 最新版本

// ==UserScript==
// @name        InfoPerk
// @namespace   perk
// @autor       Sweag
// @description Perk table -> homepage
// @include     https://www.heroeswm.ru/home.php*
// @include     https://www.lordswm.com/home.php*
// @include     http://178.248.235.15/home.php*
// @homepage    https://gf.qytechs.cn/en/scripts/378276-infoperk
// @version     1.5.2
// @grant       none
// ==/UserScript==

// fix by CheckT: include, мелкие правки, рефакторинг
// old homepage https://gf.qytechs.cn/ru/scripts/25129-infoperk

(function(){

  var url_cur = location.href;
  var url = location.protocol+'//'+location.hostname+'/';

  var switch_kukla_and_perks = true;   //поменять местами куклу и перки

  var isLords = (location.hostname == 'www.lordswm.com');

  get_table(url+'pl_info.php?id='+getPlayerId());

  return; //only functions below

  function find_place_for_perks(){
    var mana = (isLords?'Mana:':'Мана:');
    var b = document.getElementsByTagName('B');
    for(var i=0; i<b.length; i++){
      if(b[i].innerHTML == mana)
        return b[i].parentNode;
    }
    return null;
  }

  function find_place_for_kukla(){
    var last_battle = (isLords?'Last combat':'Последний бой');
    var b = document.getElementsByTagName('B');
    for(var i=0; i<b.length; i++){
      if(b[i].innerHTML == last_battle)
        return b[i].parentNode.parentNode;
    }
    return null;
  }

  function insert_table(_perk_, _kukla_){
    console.log('insert_table');
    var place_for_perks = find_place_for_perks();
    if(place_for_perks){
      place_for_perks.innerHTML += switch_kukla_and_perks?_kukla_:_perk_;
    }
    var td_place_for_kukla = find_place_for_kukla();
    if(td_place_for_kukla){
      td_place_for_kukla.innerHTML += switch_kukla_and_perks?_perk_:_kukla_;
    }
  }

  function get_table(href) {
    var xhr = new XMLHttpRequest();
    xhr.open("GET", href, true);
    xhr.overrideMimeType('text/html; charset=windows-1251');
    xhr.send();
    xhr.onreadystatechange = function() { process_xhr(xhr); }
  }

  function process_xhr(xhr){
    if (xhr.readyState != 4)
      return;

    if (xhr.status == 200) {
      var table_perk = "<div><";
      var table_kukla = "<";
      var text = xhr.responseText.split('table');
        for(var i=1; i<text.length; i++){
          if(text[i].indexOf('showperkinfo.php') > -1){
            table_perk += "table" + text[i-1] + "table" + text[i];
          }
          if(text[i].indexOf('kukla') > -1){
            table_kukla += "table" + text[i-1] + "table" + text[i];
          }
        }
        table_perk += "table></div>";
        table_kukla += "table>";
        insert_table(table_perk, table_kukla);
      }
  }

  //------------
  function getPlayerId(){
    var hunter_ref = getI("//a[contains(@href, 'pl_hunter_stat')]");
      //min 2 для home; min 1 для остальных - если включены выпадающие вкладки
      //min 1 для home; min 0 для остальных - если отключены выпадающие вкладки
    if ( !hunter_ref || hunter_ref.snapshotLength == 0 || (hunter_ref.snapshotLength == 1 && location.pathname == '/home.php') ) {
        //отключены вкладки или разлогин
    } else {
      return hunter_ref.snapshotItem(0).href.split('?id=')[1];
    }
  }

  function getI(xpath,elem){return document.evaluate(xpath,(elem?elem:document),null,XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,null);}

})();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址