-:TA Chat Colorize:-

Let's change username color (chat) in dependence of role in alliance.

2015-10-02 या दिनांकाला. सर्वात नवीन आवृत्ती पाहा.

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey, Greasemonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

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

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

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

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्क्रिप्ट व्यवस्थापक एक्स्टेंशन इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्क्रिप्ट व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्टाईल व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

// ==UserScript==
// @name        -:TA Chat Colorize:-
// @description Let's change username color (chat) in dependence of role in alliance.
// @namespace   http*://prodgame*.alliances.commandandconquer.com/*/index.aspx*
// @include     https://prodgame*.alliances.commandandconquer.com/*/index.aspx*
// @icon        http://i.imgur.com/0dweZMu.png
// @version     0.1.2
// @author      der_flake
// ==/UserScript==
(function ()
{
  var ta_chat_colorize_main = function ()
  {
    function ta_chat_initialize()
    {
      console.log('-:TA Chat Colorize:- loaded');
      // just variables
      var players = ClientLib.Data.MainData.GetInstance().get_Alliance().get_MemberDataAsArray();
      var alliance_roles = ClientLib.Data.MainData.GetInstance().get_Alliance().get_Roles().d;
      var colors = [
        {
          name: 'Leader',
          color: '#ff7878'
        },
        {
          name: 'Second Commander',
          color: '#ca91d4'
        },
        {
          name: 'Officer',
          color: '#fdd94b'
        },
        {
          name: 'Veteran',
          color: '#4ec49f'
        },
        {
          name: 'Member',
          color: '#a5f25b'
        },
        {
          name: 'Newbe',
          color: '#a5f25b'
        },
        {
          name: 'Inactive',
          color: '#ababab'
        }
      ];
      var role_colors = {
      };
      var colorize_comments = false;
      var pre_css = '';
      // get correct role id
      for (var akey in alliance_roles)
      {
        for (var ckey in colors)
        {
          if (colors[ckey].name == alliance_roles[akey].Name) {
            role_colors[alliance_roles[akey].Id] = colors[ckey].color;
          }
        }
      }
      // create styles for each player
      for (var pkey in players)
      {
        var current_player = players[pkey];
        if (typeof role_colors[current_player.Role] != 'undefined')
        {
          if (colorize_comments)
          pre_css += '#CHAT_SENDER_' + current_player.Name + ',#CHAT_SENDER_' + current_player.Name + ' + * {color: ' + role_colors[current_player.Role] + '}';
           else
          pre_css += '#CHAT_SENDER_' + current_player.Name + ' {color: ' + role_colors[current_player.Role] + '}';
        }
      }
      if (pre_css !== '')
      {
        var tachatStyle = document.createElement('style');
        tachatStyle.innerHTML = pre_css;
        if (/commandandconquer\.com/i.test(document.domain)) {
          document.getElementsByTagName('head') [0].appendChild(tachatStyle);
          console.log('-:TA Chat Colorize:- CSS loaded');
        }
      }
    }
    function tachat_checkIfLoaded() {
      try {
        if (typeof qx != 'undefined') {
          if (qx.core.Init.getApplication() && qx.core.Init.getApplication().getMenuBar()) {
            // @TODO try to find other method to make ClientLib "WORKABLE"
            window.setTimeout(ta_chat_initialize, 15000);
          } else
          window.setTimeout(tachat_checkIfLoaded, 1000);
        } else {
          window.setTimeout(tachat_checkIfLoaded, 1000);
        }
      } catch (e) {
        console.log('tachat_checkIfLoaded: ', e);
      }
    }
    if (/commandandconquer\.com/i.test(document.domain)) {
      window.setTimeout(tachat_checkIfLoaded, 1000);
    }
  }
  var tachatScript = document.createElement('script');
  tachatScript.innerHTML = '(' + ta_chat_colorize_main.toString() + ')();';
  tachatScript.type = 'text/javascript';
  if (/commandandconquer\.com/i.test(document.domain)) {
    document.getElementsByTagName('head') [0].appendChild(tachatScript);
  }
}) ();