-:TA Chat Colorize:-

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

目前為 2015-10-01 提交的版本,檢視 最新版本

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

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

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

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

你需要先安裝一款使用者腳本管理器擴展,比如 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.1
// @author      der_flake
// ==/UserScript==
(function ()
{
  var ta_chat_colorize_main = function ()
  {
    function ta_chat_initialize()
    {
      console.log('-:TA Chat Colorize:- loaded');

      var role_colors = {
        168: '#5b7b37', // inactive
        //166: '#a5f25b', // member
        165: '#42B27C', // veteran
        164: '#FFEB5F', // officer
        163: '#a75fb4', // sic
        162: '#FF6060', // cic
      }
      var players = ClientLib.Data.MainData.GetInstance().get_Alliance().get_MemberDataAsArray();
      var colorize_comments = false;
      var pre_css = '';

      for (var key in players)
      {
        var current_player = players[key];
        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.Rank] + '}';
        	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);
  }
})();