Nexus Clash Colour Messages

Message colour coding for Nexus Clash Browser Game

  1. // ==UserScript==
  2. // @name Nexus Clash Colour Messages
  3. // @namespace http://userscripts.org/users/125692
  4. // @description Message colour coding for Nexus Clash Browser Game
  5. // @include http://nexusclash.com/modules.php?name=Game*
  6. // @include http://www.nexusclash.com/modules.php?name=Game*
  7. // @exclude http://nexusclash.com/modules.php?name=Game&op=disconnect
  8. // @exclude http://www.nexusclash.com/modules.php?name=Game&op=disconnect
  9. // @grant none
  10. // @version 1.2
  11. // ==/UserScript==
  12.  
  13. //just a cut and paste of the relevant sections of my larger tweaks script.
  14.  
  15. (function() {
  16.  
  17. function addGlobalStyle(css) {
  18. var head, style;
  19. head = document.getElementsByTagName('head')[0];
  20. if (!head) { return; }
  21. style = document.createElement('style');
  22. style.type = 'text/css';
  23. style.innerHTML = css;
  24. head.appendChild(style);
  25. }
  26. //styles for pet messages
  27. addGlobalStyle('div.MagePetHit {font-size:smaller;color:lightcoral ! important;padding-left:4em;}');
  28. addGlobalStyle('div.MagePetHitMe {font-size:smaller;color:red ! important;padding-left:4em;}');
  29. addGlobalStyle('div.MagePetKill {font-size:smaller;color:crimson;padding-left:4em;}');
  30. addGlobalStyle('div.MagePetMiss {font-size:smaller;color:#CAA083;padding-left:4em;}');
  31. addGlobalStyle('div.MagePetHealOthers {font-size:smaller;color:5050aa;padding-left:4em;}');
  32. addGlobalStyle('div.MagePetHealMe {font-size:smaller;color:0808aa;padding-left:4em;}');
  33. addGlobalStyle('div.MagePetRejuv {font-size:smaller;color:aa50aa;padding-left:4em;}');
  34. addGlobalStyle('div.MagePetDespawn {font-size:smaller;color:ff8000;padding-left:4em;}');
  35. //styles for player attack messages
  36. addGlobalStyle('div.MageAttackHit {color:red ! important;}');
  37. addGlobalStyle('div.MageAttackMiss {color:deeppink;}');
  38. addGlobalStyle('div.MageAttacked {color:red;font-weight:600}');
  39. //environmental damage
  40. addGlobalStyle('div.MageAttackedbyEnvironment {color:red;font-weight:100}');
  41. //player is healed
  42. addGlobalStyle('div.MageHealed {color:0808aa;}');
  43. //style for achievement messages
  44. addGlobalStyle('div.MageAchievement {font-size:smaller;padding-left:4em;}');
  45. addGlobalStyle('span.MageAchievementColour {color:aa0000;}');
  46. addGlobalStyle('div.MageSpeech {color:dodgerblue;}');
  47. addGlobalStyle('div.MageAction {color:aaaaff;}');
  48. addGlobalStyle('div.MageWhisper{color:MediumOrchid;}');
  49. addGlobalStyle('span.MageMe{color:darkblue;}');
  50. addGlobalStyle('div.MageReceivedSomething{color:ff8040;}');
  51. addGlobalStyle('div.MageCraft{color:8d4f9d;}');
  52. addGlobalStyle('div.MageSearchNothing{color:8c8c55;}');
  53. addGlobalStyle('div.MageSearchYay{color:8c8c00;}');
  54.  
  55. // TWEAK 8 Color hits/misses (and make message box bigger and resizable)
  56. if(document.getElementById("Messages")){
  57. var messages=document.getElementById("Messages");
  58. if (!(messages.previousElementSibling.innerHTML.match(/This Week/))){//ensure we dont do this on log page
  59. //messages.style.height="145px";//make the message box a bit bigger
  60. messages.style.resize = "vertical";//allow resizing
  61. }
  62. var alonglist=messages.innerHTML.split("\n");
  63. var a=0;//for testing. count number of certain matches depending on where I left a++;
  64. var b=0;//for testing. count number of certain matches depending on where I left b++;
  65.  
  66. for (i=0;i<alonglist.length;i++){ //For each line
  67. //first check every string for the dreaded a(n) and fix them
  68. alonglist[i]=alonglist[i].replace(/( a)(\(?(n)\)?( [AEIOUaeiou])|\(?n\)?( [^AEIOUaeiou]))/g,'$1$3$4$5');//fix all ' a(n)'
  69. //regex string for replacing a(n)
  70. //a.replace(/((a)\((n)\)( [AEIOUaeiou])|(a)\(()n\)( [^AEIOUaeiou]))/g,'$2$3$4$5$6$7')
  71.  
  72. //You attack and hit
  73. if(alonglist[i].match(/(- (\(\d+ times\) )?You attack .* with your .* and hit for .* damage..*)<br>/)){
  74. alonglist[i]="<div class='MageAttackHit'>"+alonglist[i]+"</div>";//colour hits red
  75. }
  76. //You attack and miss
  77. else if(alonglist[i].match(/(- (\(\d+ times\) )?You attack .* with your .* and miss..*)<br>/)){
  78. alonglist[i]="<div class='MageAttackMiss'>"+alonglist[i]+"</div>";//colour misses deeppink
  79. }
  80. //You defend
  81. else if(alonglist[i].match(/-( (\(\d+ times\) )?.* attacked you with .*)<br>/)){
  82. alonglist[i]="<div class='MageAttacked'>!"+alonglist[i].substr(1)+"</div>";
  83. }
  84. //Environmental damage
  85. else if(alonglist[i].match(/-( (\(\d+ times\) )?.* (Your action causes you to|You|you) take \d+ point(s)? of( \b[a-z]+\b)? damage(.|!)?.*)<br>/)){
  86. alonglist[i]="<div class='MageAttackedbyEnvironment'>!"+alonglist[i].substr(1)+"</div>";
  87. }
  88.  
  89. //and make pet lines smaller font? serach for ', belonging to'
  90. //pet is rejuved
  91. //- Your pet, Judgemaster, has been rejuvenated. You spent 15 Magic Points. (2013-06-25 02:17:16).
  92. //FFS two spaces before 'You spent...'
  93. else if(alonglist[i].match(/(- (\(\d+ times\) )?Your pet, .* has been rejuvenated. You spent \d+ Magic Point.*)<br>/)){
  94. alonglist[i]="<div class='MagePetRejuv'>"+alonglist[i]+"</div>";
  95. }
  96.  
  97. //Player is healed by pet
  98. //- Aethersprite, belonging to kiwimage, healed you. You gain 10 hit points. The poison affecting you has been cured. (2013-06-18 14:12:52).
  99. else if(alonglist[i].match(/(- (\(\d+ times\) )?.* belonging to .*, healed you. You gain \d+ hit point(s)?.*)<br>/)){
  100. alonglist[i]="<div class='MagePetHealMe'>"+alonglist[i]+"</div>";
  101. }
  102. //Player healed by will-o-wisp(possibly also wight)
  103. //- Will-O-Wisp, belonging to Mr Scavvy, has funneled life energy to you, healing you of 1 points of damage. (2013-06-25 02:38:02).
  104. else if(alonglist[i].match(/(- (\(\d+ times\) )?.* belonging to .*, has funneled life energy to you, healing you of \d+ points of damage.*)<br>/)){
  105. alonglist[i]="<div class='MagePetHealMe'>"+alonglist[i]+"</div>";
  106. }
  107. //Own pets healing others
  108. //- Aethersprite, belonging to kiwimage, healed German Shepherd for 10 hit points. (2013-06-18 07:44:32).
  109. else if(alonglist[i].match(/(- (\(\d+ times\) )?.*, belonging to .*, healed .* for \d+ hit point.*)<br>/)){
  110. alonglist[i]="<div class='MagePetHealOthers'>"+alonglist[i]+"</div>";
  111. }
  112. //own pets attacking
  113. else if(alonglist[i].match(/(- (\(\d+ times\) )?Your pet .* and hit for .*)<br>/)){
  114. alonglist[i]="<div class='MagePetHit'>"+alonglist[i]+"</div>";
  115. a++;//MAGE TESTING
  116. }
  117. //bring hit by others pets made slightly more important.(though if you seeing this you are probably dead.)
  118. else if(alonglist[i].match(/(- (\(\d+ times\) )?.*, belonging to .* and hit for .*)<br>/)){
  119. alonglist[i]="<div class='MagePetHitMe'>!"+alonglist[i].substr(1)+"</div>";
  120. a++;//MAGE TESTING
  121. }
  122. else if(alonglist[i].match(/(- (\(\d+ times\) )?(Your pet |[^,].*, belonging to).*, killing them!.*)<br>/)){
  123. alonglist[i]="<div class='MagePetKill'>"+alonglist[i]+"</div>";
  124. }
  125. else if(alonglist[i].match(/(- (\(\d+ times\) )?(Your pet |[^,].*, belonging to).* and missed.*)<br>/)){
  126. alonglist[i]="<div class='MagePetMiss'>"+alonglist[i]+"</div>";
  127. b++;//MAGE TESTING
  128. }
  129. //others pets attacking
  130. else if(alonglist[i].match(/-( (\(\d+ times\) )?.* attacked your pet,.*and hit for .*)<br>/)){
  131. alonglist[i]="<div class='MagePetHit'}>!"+alonglist[i].substr(1)+"</div>";//colour pet getting hit bold red with exclamation mark
  132. }
  133. else if(alonglist[i].match(/(- (\(\d+ times\) )?.* attacked your pet,.* killing it!.*)<br>/)){
  134. alonglist[i]="<div class='MagePetKill'>"+alonglist[i]+"</div>";
  135. }
  136. else if(alonglist[i].match(/(- (\(\d+ times\) )?.* attacked .* killing it!.*)<br>/)){
  137. alonglist[i]="<div class='MagePetKill'>"+alonglist[i]+"</div>";//PET MESSAGES SEEM TO BE ODDLY BORKED IN COMPARISON TO OTHERS
  138. }
  139. else if(alonglist[i].match(/(- (\(\d+ times\) )?.* attacked your pet.* and missed.*)<br>/)){
  140. alonglist[i]="<div class='MagePetMiss'>"+alonglist[i]+"</div>";//NOTE NO COMMA FOR MISS MESSAGES!
  141. }
  142. //pet despawns
  143. // - Your pet Lightspawn, a Ghoul, has despawned. (2013-06-21 19:00:07).
  144. //- Aethersprite, belonging to kiwimage, has despawned. (2013-06-18 07:49:21).
  145. else if(alonglist[i].match(/(- (\(\d+ times\) )?(Your pet .*|.*, belonging to .*,) has despawned.*)<br>/)){
  146. alonglist[i]="<div class='MagePetDespawn'>"+alonglist[i]+"</div>";
  147. }
  148. //achievement announcements
  149. else if(alonglist[i].match(/((- (\(\d+ times\) )?)<font color="#DD0000">(<b>.*<\/b>)<\/font>(.*))<br>/)){
  150. //BAH EASIER JUST TO USE REPLACE
  151. //alonglist[i]=alonglist[i].replace(/(- (\(\d+ times\) )?<)font color="#DD0000"(>.*)font>(.*)<br>/g,"<div class='MageAchievement'>$1span class='MageAchievementColour'$2</span>$3</div>");//center annoucements
  152. alonglist[i]=alonglist[i].replace(/((- (\(\d+ times\) )?)<font color="#DD0000">(<b>.*<\/b>)<\/font>(.*))<br>/,'<div class="MageAchievement">$2<span class="MageAchievementColour">$4</span>$5</div>');//center annoucements
  153. }
  154. //- <font color="#DD0000"><b><a href="modules.php?name=Game&op=character&id=4876">Abra Cadaver</a> has become a(n) Lich !</b></font> (2012-05-17 01:27:56). <br>/
  155.  
  156. //colour speech light blue
  157. else if(alonglist[i].match(/(- (\(\d+ times\) )?)([^,].*)( said, )(\".*)<br>/)){
  158. //alonglist[i]="<div class='MageSpeech'>"+alonglist[i]+"</div>";
  159. alonglist[i]=alonglist[i].replace(/(- (\(\d+ times\) )?)([^,].*) (said, )(\".*)<br>/,"<div class='MageSpeech'>$1 $3<span class='MageMe'> $4</span>$5</div>");
  160. }
  161. else if(alonglist[i].match(/(- (\(\d+ times\) )?)([^,].*)( whispered to you, saying).(\".*)<br>/)){
  162. //alonglist[i]="<div class='MageSpeech'>"+alonglist[i]+"</div>";
  163. alonglist[i]=alonglist[i].replace(/(- (\(\d+ times\) )?)([^,].*) (whispered to you, saying).(\".*)<br>/,"<div class='MageSpeech'>$1 $3<span class='MageMe'> $4, </span>$5</div>");
  164. }
  165. else if(alonglist[i].match(/(- (\(\d+ times\) )?)(You say, )(\".*)<br>/)){
  166. alonglist[i]=alonglist[i].replace(/(- (\(\d+ times\) )?)(You say, )(\".*)<br>/,"<div class='MageSpeech'>$1<span class='MageMe'>$3</span>$4</div>");
  167. }
  168. else if(alonglist[i].match(/(- (\(\d+ times\) )?You whisper, \".*)<br>/)){
  169. //alonglist[i]="<div class='MageSpeech'>"+alonglist[i]+"</div>";
  170. //Due to wanting to make the you part black but still have the initial - blue doing it with a replace.
  171. alonglist[i]=alonglist[i].replace(/(- (\(\d+ times\) )?)(You whisper, )(\".*)<br>/,"<div class='MageSpeech'>$1<span class='MageMe'>$3</span>$4</div>");
  172. }
  173. else if(alonglist[i].match(/(- (\(\d+ times\) )?[^,].* (said|say), \".*)<br>/)){
  174. alonglist[i]="<div class='MageSpeech'>"+alonglist[i]+"</div>";
  175. }
  176. else if(alonglist[i].match(/(- (\(\d+ times\) )?[^,].* (whispered to you|whisper), saying \".*)<br>/)){
  177. alonglist[i]="<div class='MageSpeech'>"+alonglist[i]+"</div>";
  178. }
  179. //colour being given something
  180. else if(alonglist[i].match(/-( (\(\d+ times\) )?[^,].* gave you a.*)<br>/)){
  181. alonglist[i]="<div class='MageReceivedSomething'>+"+alonglist[i].substr(1)+"</div>";
  182. }
  183. //colour crafting
  184. else if(alonglist[i].match(/(- (\(\d+ times\) )?You call upon your crafting skills.*)<br>/)){
  185. alonglist[i]="<div class='MageCraft'>"+alonglist[i]+"</div>";
  186. }
  187. //colour searching
  188. else if(alonglist[i].match(/(- (\(\d+ times\) )?You search and find nothing.*)<br>/)){
  189. alonglist[i]="<div class='MageSearchNothing'>"+alonglist[i]+"</div>";
  190. }
  191. else if(alonglist[i].match(/(- (\(\d+ times\) )?You search and find a.*)<br>/)){
  192. alonglist[i]="<div class='MageSearchYay'>+"+alonglist[i].substr(1)+"</div>";
  193. }
  194. //Player is healed You heal yourself and gain 10 hit points
  195. else if(alonglist[i].match(/(- (\(\d+ times\) )?.*(You heal yourself and|healed you. You) gain \d+ hit point(s)?.*)<br>/)){
  196. alonglist[i]="<div class='MageHealed'>"+alonglist[i]+"</div>";
  197. }
  198. }
  199. messages.innerHTML=alonglist.join('');
  200.  
  201. }
  202.  
  203. //EOF
  204. })();