CT_pers_note

Комментарий на странице информации о персе

Fra 04.01.2019. Se den seneste versjonen.

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

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

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

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

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

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name           CT_pers_note
// @namespace      CheckT
// @author         CheckT
// @description    Комментарий на странице информации о персе
// @version        1.0
// @encoding       utf-8
// @homepage       https://greasyfork.org/en/scripts/376319-ct-friends
// @include        https://www.heroeswm.ru/pl_info.php*
// @include        https://www.lordswm.com/pl_info.php*
// @include        http://178.248.235.15/pl_info.php*
// @grant          GM_getValue
// @grant          GM_setValue
// ==/UserScript==

(function(){
  var gm_prefix = 'ctpn_';
  initGm();
  var pl_id = getPlayerId();
  if(pl_id){
    var img_clan_war = document.querySelector('img[src*="unk_kukla.png"]');
    if(img_clan_war){
      create_input(img_clan_war);
    } else {
      var table_kukla = document.querySelector('table[background*="i/kukla"]');
      if(table_kukla){
        create_input(table_kukla);
      }
    }
    addEvent($$GM('notes'), "change", change_info);
  }

  return;
  
  function create_input(elt){
    var root_table = elt.parentNode.parentNode.parentNode.parentNode;
    var tr = root_table.insertRow(1);
    tr.innerHTML = '<td colspan="3"><input type="text" value="'+gm_get(pl_id)+'" id="'+gm_prefix+'notes" style="width:315px"/> (любой комментарий, виден только Вам)</td>';
  }

  function change_info(){
    gm_set(pl_id, $$GM('notes').value);
  }

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

  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') ) {
        //отключены вкладки или разлогин
      var ids=/pl_id=(\d+)/.exec(document.cookie);
      return ids ? ids[1] : 'unknown';
    } else {
      return hunter_ref.snapshotItem(0).href.split('?id=')[1];
    }
  }

  function $$GM(id) { return document.getElementById(gm_prefix+id); }

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

  function addChangeEvent_GM(id, func){
    addEvent($$GM(id), "change", func);
  }

  function addEvent(elem, evType, fn) {
    if(elem && fn){
      if (elem.addEventListener)
        elem.addEventListener(evType, fn, false);
      else if (elem.attachEvent)
        elem.attachEvent("on" + evType, fn);
      else
        elem["on" + evType] = fn;
    }
  }

  function gm_get(key){
    return GM_getValue(gm_prefix+key, '');
  }

  function gm_set(key, val){
    return GM_setValue(gm_prefix+key, val);
  }

  function initGm(){
    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 (!this.GM_listValues || (this.GM_listValues.toString && this.GM_listValues.toString().indexOf("not supported")>-1)) {
      this.GM_listValues=function () {
        var keys=[];
        for (var key in localStorage){
          //в K-Meleon возвращаются все опции всех скриптов
          keys.push(key);
        }
        return keys;
      }
    }
  }
})();