RainbowChat for DH1

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

当前为 2017-03-04 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name RainbowChat for DH1
  3. // @namespace http://tampermonkey.net/
  4. // @version 1.0.0
  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! Links doesn't work because of this for now! (default: "false")
  37. };
  38.  
  39.  
  40. /*
  41. * #=================#
  42. * # Update history! #
  43. * #=================#
  44. *
  45. * v1.0.0 - February 19th 2017
  46. * + Initial release! :D
  47. *
  48. * v1.x.x - Comming soon!
  49. * ? Try to fix "rainbowMSG" to support links!
  50. * ? Maybe adding choises of color sets?
  51. * ? Adding more color choises in the config!
  52. *
  53. */
  54.  
  55.  
  56. /*
  57. * #======================================================================================================================#
  58. * # I'm pretty sure you don't need to change anything below here! It's pretty much fully customizeable in the configs :) #
  59. * #======================================================================================================================#
  60. */
  61.  
  62.  
  63. 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!
  64.  
  65.  
  66. var rcColours = [
  67. ["#ff0000", "#cc0000", "#b30000"], // Red colors
  68. ["#00cc00", "#009900", "#00e600"], // Green colors
  69. ["#ff99cc", "#ff4da6", "#ff0080"], // Pink colors
  70. ["#9900cc", "#730099", "#bf00ff"], // Purple colors
  71. ["#ff9933", "#ff8000", "#ff9933"], // Orange colors
  72. ["#e6b800", "#cca300", "#b38f00"] // Gold/Yellow colors
  73. ];
  74. var rcColour = -1;
  75. var rcLastColour = -1;
  76.  
  77.  
  78. // This is a trigger for the script to make the changes!
  79. window.refreshChat = function(data) {
  80. data = newRainbowChat(data);
  81. };
  82.  
  83.  
  84. // The actually magically code is here! This code will make the chat colors change when the above code is triggered and need this code!
  85. // All errors here that Tampermonkey tell you "'someVar' is not defined." is allready in Smitty's scripts!
  86. function newRainbowChat(data) {
  87. var chatbox = document.getElementById("chat-area-div");
  88. var output = data;
  89.  
  90. var splitArray = data.split("~");
  91. var userChatting = splitArray[0];
  92. var levelChat = splitArray[1];
  93. var tag = splitArray[2];
  94. var icon = splitArray[3];
  95. var message = splitArray[4];
  96. var isPM = splitArray[5];
  97.  
  98. for(var i = 0; i < mutedPeople.length; i++) { if(mutedPeople[i] == userChatting) return; }
  99.  
  100. var chatSegment = "";
  101.  
  102. // Random color!
  103. while (rcColour === rcLastColour) { rcColour = getRandomArbitrary(0, rcColours.length); }
  104. rcLastColour = rcColour;
  105. var myColour = rcColours[rcColour][getRandomArbitrary(0, rcColours[rcColour].length)];
  106.  
  107. var msg = "";
  108. if(config.rainbowMSG === true) {
  109. msg = "<span style='color:" + myColour + "'>" + message + "</span>";
  110. } else {
  111. msg = message;
  112. }
  113.  
  114. var timeStamp = "";
  115. if(config.rainbowTime === true) {
  116. timeStamp = "<span style='color:" + myColour + "'>" + timeFetch() + "</span>";
  117. } else {
  118. timeStamp = timeFetch();
  119. }
  120.  
  121. var totalTextDiv = "";
  122. if(isPM == 1)
  123. {
  124.  
  125. chatSegment = "<span style='color:purple'>PM from " + "<span style='cursor:pointer;' oncontextmenu='searchPlayerHicores(\""+userChatting+"\");return false;' onclick='preparePM(\""+userChatting+"\")'>"+userChatting+"</span>" +": " + message + "</span>";
  126. chatSegment += "<br />";
  127. lastPMFrom = userChatting;
  128. totalTextDiv = chatbox.innerHTML + timeStamp + chatSegment;
  129. chatbox.innerHTML = totalTextDiv;
  130. if(isAutoScrolling) { $("#chat-area-div").animate({ scrollTop: 55555555 }, 'slow'); }
  131. return;
  132. }
  133. if(isPM == 2)
  134. {
  135. chatSegment = "<span style='color:purple'>sent PM to " + "<span style='cursor:pointer;' oncontextmenu='searchPlayerHicores(\""+userChatting+"\");return false;' onclick='preparePM(\""+userChatting+"\")'>"+userChatting+"</span>" +": " + message + "</span>";
  136. chatSegment += "<br />";
  137. totalTextDiv = chatbox.innerHTML + timeStamp + chatSegment;
  138. lastPMFrom = userChatting;
  139. chatbox.innerHTML = totalTextDiv;
  140. if(isAutoScrolling) { $("#chat-area-div").animate({ scrollTop: 55555555 }, 'slow'); }
  141. return;
  142. }
  143. if(isPM == 3) //yell message
  144. {
  145. chatSegment = "<span style='color:#0066ff;'><span class='chat-tag-yell'>Server Message</span> " + message + " </span>";
  146. chatSegment += "<br />";
  147. totalTextDiv = chatbox.innerHTML + timeStamp + chatSegment;
  148. lastPMFrom = userChatting;
  149. chatbox.innerHTML = totalTextDiv;
  150. if(isAutoScrolling) { $("#chat-area-div").animate({ scrollTop: 55555555 }, 'slow'); }
  151. return;
  152. }
  153.  
  154. if(config.removeIcons === false) {
  155. 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;
  156. } 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;
  157. } 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;
  158. } 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;
  159. } 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;
  160. } 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;
  161. } 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;
  162. } 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;
  163. } 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;
  164. } 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;
  165. } 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;
  166. } 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;
  167. } 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;
  168. } 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;
  169. } 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; }
  170. } // End of "removeIcons"
  171.  
  172. if(tag == 1) { chatSegment += "<span><img src='images/icons/donor-icon.gif' style='vertical-align: text-top;' width='20' height='20' alt='Donor'/> ";
  173. } else if(tag == 2) { chatSegment += "<span style='color:green;'><span class='chat-tag-contributor'>Contributor</span> ";
  174. } else if(tag == 4) { chatSegment += "<span style='color:#669999;'><span class='chat-tag-mod'>Moderator</span> ";
  175. } else if(tag == 5) { chatSegment += "<span style='color:#666600;'><span class='chat-tag-dev'>Dev</span> "; }
  176.  
  177. if(config.rainbowName === true) { chatSegment += "<span style='cursor:pointer;color:" + myColour + "' oncontextmenu='searchPlayerHicores(\"" + userChatting + "\");return false;' onclick='preparePM(\"" + userChatting + "\")'>" + userChatting + " (" + levelChat +"): </span>";
  178. } else { chatSegment += "<span style='cursor:pointer' oncontextmenu='searchPlayerHicores(\"" + userChatting + "\");return false;' onclick='preparePM(\"" + userChatting + "\")'>" + userChatting + " (" + levelChat +"): </span>"; }
  179.  
  180. //make links clickable
  181. if(isValidURL(msg) && disableUrls === 0) {
  182. var msgArray = msg.split(" ");
  183. var newString = "";
  184. var linkFound = "";
  185. for(i = 0; i < msgArray.length; i++) {
  186. if(isValidURL(msgArray[i])) {
  187. if(!msgArray[i].startsWith("http")) { linkFound = "<a style='color:#40ff00' href='http://"+msgArray[i]+"' target='_blank'>"+msgArray[i]+"</a>" + " ";
  188. } else { linkFound = "<a style='color:#40ff00' href='"+msgArray[i]+"' target='_blank'>"+msgArray[i]+"</a>" + " "; }
  189. newString += linkFound;
  190. } else { newString += msgArray[i] + " "; }
  191. }
  192. chatSegment += newString;
  193. } else { chatSegment += msg; }
  194.  
  195. chatSegment += "<span><br />";
  196.  
  197. totalTextDiv = chatbox.innerHTML + timeStamp + chatSegment;
  198. chatbox.innerHTML = totalTextDiv;
  199.  
  200. if(isAutoScrolling) { $("#chat-area-div").animate({ scrollTop: 55555555 }, 'slow'); }
  201.  
  202. return data;
  203.  
  204. }
  205.  
  206. function getRandomArbitrary(min, max) {
  207. return Math.floor(Math.random() * (max - min) + min);
  208. }