CT_friends

Комментарии на странице друзей

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name           CT_friends
// @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/friends.php
// @include        https://www.lordswm.com/friends.php
// @include        http://178.248.235.15/friends.php
// @grant          GM_getValue
// @grant          GM_setValue
// ==/UserScript==

(function(){
  var gm_prefix = 'ctfr_';
  initGm();

  var tableToFix = document.querySelector('table[class="wb"]');
  if(tableToFix){
    var tmp = tableToFix.innerHTML;
    tmp = tmp.replace(/colspan="3"/g,'colspan="4"');
    var td_regexp = /<\/td><\/tr>/g;
    var idx = -3; //3 rows header
    while(true){
      var td_arr = td_regexp.exec(tmp);
      if(!td_arr)
        break;
      idx++;
      if(idx < 1) //skip header
        continue;
      var pos = td_regexp.lastIndex-5;
      var add = '<td><input type="text" value="" id="'
        + gm_prefix + idx + '" style="width:400px"/></td>';
      tmp = tmp.slice(0, pos) + add + tmp.slice(td_regexp.lastIndex);
      td_regexp.lastIndex += add.length;
    }
    tableToFix.innerHTML = tmp;
    var pl_id_regexp=/pl_info\.php\?id=(\d+)\"/;
    for(var i=1; i<=idx; i++){
      var inp = $$GM(i);
      var tr = inp.parentNode.parentNode;
      var pl_id = pl_id_regexp.exec(tr.innerHTML)[1];
      inp.value = gm_get(pl_id);
      inp.setAttribute('data-plid',pl_id);
      addEvent(inp, "change", change_info);
    }
  }

  return;
  
  function change_info(event){
    var inp = event.target || event.srcElement;
    gm_set(inp.getAttribute('data-plid'), inp.value.trim()); 
  }

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

  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;
      }
    }
  }
})();