-:C&C TA Chat Colorize:-

Let's change the nickname color (chat only) in dependence of the role in the alliance.

  1. // ==UserScript==
  2. // @name -:C&C TA Chat Colorize:-
  3. // @description Let's change the nickname color (chat only) in dependence of the role in the alliance.
  4. // @namespace http*://prodgame*.alliances.commandandconquer.com/*/index.aspx*
  5. // @include https://prodgame*.alliances.commandandconquer.com/*/index.aspx*
  6. // @icon http://i.imgur.com/0dweZMu.png
  7. // @version 0.1.6
  8. // @author der_flake
  9. // ==/UserScript==
  10. 'use strict';
  11. (function ()
  12. {
  13. var ta_chat_colorize_main = function ()
  14. {
  15. function ta_chat_initialize()
  16. {
  17. console.log('-:C&C TA Chat Colorize:- loaded');
  18. var config = {
  19. colors: [
  20. {
  21. name: 'Leader',
  22. color: '#ff7878'
  23. },
  24. {
  25. name: 'Second Commander',
  26. color: '#ca91d4'
  27. },
  28. {
  29. name: 'Officer',
  30. color: '#fdd94b'
  31. },
  32. {
  33. name: 'Veteran',
  34. color: '#4ec49f'
  35. },
  36. {
  37. name: 'Member',
  38. color: '#a5f25b'
  39. },
  40. {
  41. name: 'Newbe',
  42. color: '#a5f25b'
  43. },
  44. {
  45. name: 'Inactive',
  46. color: '#ababab'
  47. }
  48. ],
  49. append_alliance_name_limit: 15
  50. };
  51. var options = {
  52. colorize_names: true,
  53. colorize_comments: false,
  54. append_abbr: true
  55. };
  56. // module functions
  57. var mod = {
  58. colorize: function () {
  59. var css_colors = '';
  60. var role_colors = [
  61. ];
  62. var LibData = ClientLib.Data.MainData.GetInstance().get_Alliance();
  63. // get correct role id
  64. var alliance_roles = LibData.get_Roles().d;
  65. for (var akey in alliance_roles)
  66. {
  67. for (var ckey in config.colors)
  68. {
  69. if (config.colors[ckey].name == alliance_roles[akey].Name) {
  70. role_colors[alliance_roles[akey].Id] = config.colors[ckey].color;
  71. }
  72. }
  73. }
  74. // assign styles to the each player of the current alliance
  75.  
  76. var players = LibData.get_MemberDataAsArray();
  77. for (var pkey in players)
  78. {
  79. var current_player = players[pkey];
  80. if (typeof role_colors[current_player.Role] != 'undefined')
  81. {
  82. if (options.colorize_comments) {
  83. css_colors += '[color="#a5f25b"] #CHAT_SENDER_' + current_player.Name + ',[color="#a5f25b"] #CHAT_SENDER_' + current_player.Name + ' + * {color: ' + role_colors[current_player.Role] + '}';
  84. } else {
  85. css_colors += '[color="#a5f25b"] #CHAT_SENDER_' + current_player.Name + ' {color: ' + role_colors[current_player.Role] + '}';
  86. }
  87. }
  88. }
  89. append_styles(css_colors);
  90. },
  91. /**
  92. * Append the alliance abbreviation to the player's name
  93. * @example der_flake -> #RoF der_flake
  94. */
  95. add_abbr: function () {
  96. //get top [append_alliance_name_limit] alliances by rating
  97. ClientLib.Net.CommunicationManager.GetInstance().SendSimpleCommand('RankingGetData', {
  98. firstIndex: 0,
  99. lastIndex: config.append_alliance_name_limit - 1,
  100. view: 1,
  101. rankingType: 0,
  102. sortColumn: 2,
  103. ascending: true
  104. }, phe.cnc.Util.createEventDelegate(ClientLib.Net.CommandResult, this, function (context, data) {
  105. if (data !== null)
  106. {
  107. for (var i = 0; i < data.a.length; i++)
  108. {
  109. var alliance_id = data.a[i]['a'];
  110. // get alliance players
  111. ClientLib.Net.CommunicationManager.GetInstance().SendSimpleCommand('GetPublicAllianceInfo', {
  112. id: alliance_id
  113. }, phe.cnc.Util.createEventDelegate(ClientLib.Net.CommandResult, this, function (context, alliance_data) {
  114. var alliance_shortname = alliance_data['a'],
  115. alliance_players = alliance_data['m'],
  116. css_names = [
  117. ];
  118. for (var akey in alliance_players)
  119. {
  120. css_names.push('[color="#4becff"] #CHAT_SENDER_' + alliance_players[akey]['n'] + ':after');
  121. }
  122. var temp_css = css_names.join(',') + ' {content: " #' + alliance_shortname + '";opacity: .6;font-size: 11px;}';
  123. append_styles(temp_css);
  124. }), null);
  125. }
  126. }
  127. }), null);
  128. }
  129. }
  130. if (options.colorize_names) {
  131. mod.colorize();
  132. }
  133. if (options.append_abbr)
  134. {
  135. mod.add_abbr();
  136. }
  137. }
  138. function append_styles(css) {
  139. document.getElementsByTagName('style') [0].innerHTML += css;
  140. }
  141. function tachat_checkIfLoaded() {
  142. try {
  143. if (typeof qx != 'undefined') {
  144. if (qx.core.Init.getApplication() && qx.core.Init.getApplication().getMenuBar()) {
  145. // @TODO try to find other method to make ClientLib "WORKABLE"
  146. window.setTimeout(ta_chat_initialize, 15000);
  147. } else
  148. window.setTimeout(tachat_checkIfLoaded, 1000);
  149. } else {
  150. window.setTimeout(tachat_checkIfLoaded, 1000);
  151. }
  152. } catch (e) {
  153. console.log('tachat_checkIfLoaded: ', e);
  154. }
  155. }
  156. if (/commandandconquer\.com/i.test(document.domain)) {
  157. window.setTimeout(tachat_checkIfLoaded, 1000);
  158. }
  159. }
  160. var tachatScript = document.createElement('script');
  161. tachatScript.innerHTML = '(' + ta_chat_colorize_main.toString() + ')();';
  162. tachatScript.type = 'text/javascript';
  163. if (/commandandconquer\.com/i.test(document.domain)) {
  164. document.getElementsByTagName('head') [0].appendChild(tachatScript);
  165. }
  166. }) ();