RainbowChat for DH1 (Adding DH2 later)

This script is just amazing! Check the script for some configs!

当前为 2017-02-22 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name RainbowChat for DH1 (Adding DH2 later)
  3. // @namespace http://tampermonkey.net/
  4. // @version 1.0.1
  5. // @description This script is just amazing! Check the script for some configs!
  6. // @author Lasse98brus
  7. // @match http://www.diamondhunt.co/DH1/game.php
  8. // @run-at document-idle
  9. // @grant none
  10. // ==/UserScript==
  11. /* jshint -W097 */
  12. 'use strict';
  13.  
  14.  
  15. /*
  16. * #=================================================================================================================================================================================================#
  17. * # Welcome to my RainbowChat script for both DH1 and DH2 :D My name is Lasse98brus and I did create this script because Amyjane1991 said she had the old DHRainbowChat that doesn't work anymore! #
  18. * # I pretty much had to change the whole script! So please don't this with the original DHRainbowChat! This script is built to be as stable as possible! #
  19. * # #
  20. * # If you like my script and my work with it, and you feel to support my work! Feel free to donate to me with PayPal :D my PayPal: lasse.brustad@gmail.com #
  21. * #=================================================================================================================================================================================================#
  22. */
  23.  
  24.  
  25. // Some configs to easily choose the futures that YOU like! :D
  26. var config = {
  27. // Here you can just change between "true" and "false" before you login to the game! :)
  28. "rainbowTime" : false, // Set to "true" to enable rainbow timestamps! This will color timestamps for server messages too (default: "false")
  29. "rainbowName" : true, // Set to "false" to disable rainbow names! (default: "true")
  30. "removeIcons" : false, // Set to "true" to remove all icons in chat, doesn't remove donor icon! (default: "false")
  31.  
  32. // Futures under here does have multiple choises! Read the end of the lines to know whats working ad not!
  33. // Unfortunately it's nothing to configure here yet!
  34.  
  35. // Uder development! Something isn't working as well!
  36. "rainbowMSG" : false // Under development! This works pretty good! But links doesn't work with it! (default is "false" because of the problems)
  37. };
  38.  
  39.  
  40. /*
  41. * #=================#
  42. * # Update history! #
  43. * #=================#
  44. *
  45. * v1.0.0 - February 19th 2017
  46. * + Initial release! :D
  47. *
  48. * v1.0.1 - February 22th 2017
  49. * + Updated the userscript to run just in DH1 for now! Adding DH2 later :D
  50. *
  51. * v1.x.x - Comming soon!
  52. * ? Try to fix "rainbowMSG" to support links!
  53. * ? Maybe adding choises of color sets?
  54. * ? Adding more color choises in the config!
  55. *
  56. */
  57.  
  58.  
  59. /*
  60. * #======================================================================================================================#
  61. * # I'm pretty sure you don't need to change anything below here! It's pretty much fully customizeable in the configs :) #
  62. * #======================================================================================================================#
  63. */
  64.  
  65.  
  66. document.getElementById("chat-area-div").style = "background-color:#0c0c0c;color:#999!important;"; // Please just let this be! this makes the chat look a lot better with the colors used in this script!
  67.  
  68.  
  69. var rcColours = [
  70. ["#ff0000", "#cc0000", "#b30000"], // Red colors
  71. ["#00cc00", "#009900", "#00e600"], // Green colors
  72. ["#ff99cc", "#ff4da6", "#ff0080"], // Pink colors
  73. ["#9900cc", "#730099", "#bf00ff"], // Purple colors
  74. ["#ff9933", "#ff8000", "#ff9933"], // Orange colors
  75. ["#e6b800", "#cca300", "#b38f00"] // Gold/Yellow colors
  76. ];
  77. var rcColour = -1;
  78. var rcLastColour = -1;
  79.  
  80.  
  81. // This is a trigger for the script to make the changes!
  82. window.refreshChat = function(data) {
  83. data = newRainbowChat(data);
  84. };
  85.  
  86.  
  87. // The actually magically code is here! This code will make the chat colors change when the above code is triggered and need this code!
  88. // All errors here that Tampermonkey tell you "'someVar' is not defined." is allready in Smitty's scripts!
  89. function newRainbowChat(data) {
  90. var chatbox = document.getElementById("chat-area-div");
  91. var output = data;
  92.  
  93. var splitArray = data.split("~");
  94. var userChatting = splitArray[0];
  95. var levelChat = splitArray[1];
  96. var tag = splitArray[2];
  97. var icon = splitArray[3];
  98. var message = splitArray[4];
  99. var isPM = splitArray[5];
  100.  
  101. for(var i = 0; i < mutedPeople.length; i++) { if(mutedPeople[i] == userChatting) return; }
  102.  
  103. var chatSegment = "";
  104.  
  105. // Random color!
  106. while (rcColour === rcLastColour) { rcColour = getRandomArbitrary(0, rcColours.length); }
  107. rcLastColour = rcColour;
  108. var myColour = rcColours[rcColour][getRandomArbitrary(0, rcColours[rcColour].length)];
  109.  
  110. var msg = "";
  111. if(config.rainbowMSG === true) {
  112. msg = "<span style='color:" + myColour + "'>" + message + "</span>";
  113. } else {
  114. msg = message;
  115. }
  116.  
  117. var timeStamp = "";
  118. if(config.rainbowTime === true) {
  119. timeStamp = "<span style='color:" + myColour + "'>" + timeFetch() + "</span>";
  120. } else {
  121. timeStamp = timeFetch();
  122. }
  123.  
  124. var totalTextDiv = "";
  125. if(isPM == 1)
  126. {
  127.  
  128. chatSegment = "<span style='color:purple'>PM from " + "<span style='cursor:pointer;' oncontextmenu='searchPlayerHicores(\""+userChatting+"\");return false;' onclick='preparePM(\""+userChatting+"\")'>"+userChatting+"</span>" +": " + message + "</span>";
  129. chatSegment += "<br />";
  130. lastPMFrom = userChatting;
  131. totalTextDiv = chatbox.innerHTML + timeStamp + chatSegment;
  132. chatbox.innerHTML = totalTextDiv;
  133. if(isAutoScrolling) { $("#chat-area-div").animate({ scrollTop: 55555555 }, 'slow'); }
  134. return;
  135. }
  136. if(isPM == 2)
  137. {
  138. chatSegment = "<span style='color:purple'>sent PM to " + "<span style='cursor:pointer;' oncontextmenu='searchPlayerHicores(\""+userChatting+"\");return false;' onclick='preparePM(\""+userChatting+"\")'>"+userChatting+"</span>" +": " + message + "</span>";
  139. chatSegment += "<br />";
  140. totalTextDiv = chatbox.innerHTML + timeStamp + chatSegment;
  141. lastPMFrom = userChatting;
  142. chatbox.innerHTML = totalTextDiv;
  143. if(isAutoScrolling) { $("#chat-area-div").animate({ scrollTop: 55555555 }, 'slow'); }
  144. return;
  145. }
  146. if(isPM == 3) //yell message
  147. {
  148. chatSegment = "<span style='color:#0066ff;'><span class='chat-tag-yell'>Server Message</span> " + message + " </span>";
  149. chatSegment += "<br />";
  150. totalTextDiv = chatbox.innerHTML + timeStamp + chatSegment;
  151. lastPMFrom = userChatting;
  152. chatbox.innerHTML = totalTextDiv;
  153. if(isAutoScrolling) { $("#chat-area-div").animate({ scrollTop: 55555555 }, 'slow'); }
  154. return;
  155. }
  156.  
  157. if(config.removeIcons === false) {
  158. if(icon == 1) { chatSegment = "<img title='Maxed Skills' src='images/icons/stats.png' style='vertical-align: text-top;' width='20' height='20' alt='Maxed Skills'/>" + chatSegment;
  159. } else if(icon == 2) { chatSegment = "<img title='Master in Mining' src='images/icons/pickaxe.png' style='vertical-align: text-top;' width='20' height='20' alt='Master in Mining'/>" + chatSegment;
  160. } else if(icon == 3) { chatSegment = "<img title='Master in Crafting' src='images/icons/anvil.png' style='vertical-align: text-top;' width='20' height='20' alt='Master in Crafting'/>" + chatSegment;
  161. } else if(icon == 4) { chatSegment = "<img title='Master in Brewing' src='images/brewing/vialofwater_chat.png' style='vertical-align: text-top;' width='20' height='20' alt='Master in Brewinghiscores'/>" + chatSegment;
  162. } else if(icon == 5) { chatSegment = "<img title='Master in Farming' src='images/icons/watering-can.png' style='vertical-align: text-top;' width='20' height='20' alt='Master in Farming'/>" + chatSegment;
  163. } else if(icon == 6) { chatSegment = "<img title='Hardcore Account' src='images/icons/hardcoreIcon.png' style='vertical-align: text-top;' width='20' height='20' alt='Hardcore Account'/>" + chatSegment;
  164. } else if(icon == 7) { chatSegment = "<img title='Halloween 2015' src='images/icons/halloween2015.png' style='vertical-align: text-top;' width='20' height='20' alt='Halloween 2015'/>" + chatSegment;
  165. } else if(icon == 8) { chatSegment = "<img title='Halloween 2015' src='images/icons/archaeology.png' style='vertical-align: text-top;' width='20' height='20' alt='Halloween 2015'/>" + chatSegment;
  166. } else if(icon == 9) { chatSegment = "<img title='Chirstmas 2015' src='images/sigils/christmas2015.png' style='vertical-align: text-top;' width='20' height='20' alt='Halloween 2015'/>" + chatSegment;
  167. } else if(icon == 10) { chatSegment = "<img title='Master in Farming' src='images/magic/wizardHatIcon.png' style='vertical-align: text-top;' width='20' height='20' alt='Master in Farming'/>" + chatSegment;
  168. } else if(icon == 11) { chatSegment = "<img title='Holiday' src='images/sigils/easter2016.png' style='vertical-align: text-top;' width='20' height='20' alt='Holiday Sigil'/>" + chatSegment;
  169. } else if(icon == 12) { chatSegment = "<img title='COOP' src='images/icons/groupTaskBadge5.png' style='vertical-align: text-top;' width='20' height='20' alt='COOP'/>" + chatSegment;
  170. } else if(icon == 13) { chatSegment = "<img title='cooking master' src='images/icons/cookingskill.png' style='vertical-align: text-top;' width='20' height='20' alt='Cooking Master'/>" + chatSegment;
  171. } else if(icon == 14) { chatSegment = "<img title='Halloween 2016' src='images/sigils/halloween2016.png' style='vertical-align: text-top;' width='20' height='20' alt='Halloween 2016'/>" + chatSegment;
  172. } else if(icon == 15) { chatSegment = "<img title='Chirstmas 2016' src='images/sigils/christmas2016.png' style='vertical-align: text-top;' width='20' height='20' alt='Christmas 2016'/>" + chatSegment; }
  173. } // End of "removeIcons"
  174.  
  175. if(tag == 1) { chatSegment += "<span><img src='images/icons/donor-icon.gif' style='vertical-align: text-top;' width='20' height='20' alt='Donor'/> ";
  176. } else if(tag == 2) { chatSegment += "<span style='color:green;'><span class='chat-tag-contributor'>Contributor</span> ";
  177. } else if(tag == 4) { chatSegment += "<span style='color:#669999;'><span class='chat-tag-mod'>Moderator</span> ";
  178. } else if(tag == 5) { chatSegment += "<span style='color:#666600;'><span class='chat-tag-dev'>Dev</span> "; }
  179.  
  180. if(config.rainbowName === true) { chatSegment += "<span style='cursor:pointer;color:" + myColour + "' oncontextmenu='searchPlayerHicores(\"" + userChatting + "\");return false;' onclick='preparePM(\"" + userChatting + "\")'>" + userChatting + " (" + levelChat +"): </span>";
  181. } else { chatSegment += "<span style='cursor:pointer' oncontextmenu='searchPlayerHicores(\"" + userChatting + "\");return false;' onclick='preparePM(\"" + userChatting + "\")'>" + userChatting + " (" + levelChat +"): </span>"; }
  182.  
  183. //make links clickable
  184. if(isValidURL(msg) && disableUrls === 0) {
  185. var msgArray = msg.split(" ");
  186. var newString = "";
  187. var linkFound = "";
  188. for(i = 0; i < msgArray.length; i++) {
  189. if(isValidURL(msgArray[i])) {
  190. if(!msgArray[i].startsWith("http")) { linkFound = "<a style='color:#40ff00' href='http://"+msgArray[i]+"' target='_blank'>"+msgArray[i]+"</a>" + " ";
  191. } else { linkFound = "<a style='color:#40ff00' href='"+msgArray[i]+"' target='_blank'>"+msgArray[i]+"</a>" + " "; }
  192. newString += linkFound;
  193. } else { newString += msgArray[i] + " "; }
  194. }
  195. chatSegment += newString;
  196. } else { chatSegment += msg; }
  197.  
  198. chatSegment += "<span><br />";
  199.  
  200. totalTextDiv = chatbox.innerHTML + timeStamp + chatSegment;
  201. chatbox.innerHTML = totalTextDiv;
  202.  
  203. if(isAutoScrolling) { $("#chat-area-div").animate({ scrollTop: 55555555 }, 'slow'); }
  204.  
  205. return data;
  206.  
  207. }
  208.  
  209. function getRandomArbitrary(min, max) {
  210. return Math.floor(Math.random() * (max - min) + min);
  211. }