DH1 SuperChat

This is a script that changes the chat to be amazing and improved from the original!

  1. // ==UserScript==
  2. // @name DH1 SuperChat
  3. // @namespace http://tampermonkey.net/
  4. // @version 1.2.3
  5. // @description This is a script that changes the chat to be amazing and improved from the original!
  6. // @author Lasse98brus
  7. // @match https://dh2.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. * # Welcome to my RainbowChat script for DH1 :D My name is Lasse98brus and I did create this script because Amyjane1991 said she had the old DHRainbowChat that doesn't work anymore! #
  17. * # 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! #
  18. * # #
  19. * # 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 #
  20. * #=====================================================================================================================================================================================#
  21. */
  22. // Some configs to easily choose the futures that YOU like! :D
  23. var config,
  24. // Here you can just change between "true" and "false" before you login to the game! :)
  25. rainbowTime= false, // Set to "true" to enable rainbow timestamps! (default: "false")
  26. rainbowName= true, // Set to "false" to disable rainbow names! (default: "true")
  27. rainbowMSG = false, // Set to true to enable rainbow messages! (default: "false")
  28. removeIcons= false // Set to "true" to remove all icons in chat, doesn't remove donor icon! (default: "false")
  29. ;
  30.  
  31. /*
  32. * #================#
  33. * # Chat Commands! #
  34. * #================#
  35. *
  36. * # This "[alt1|alt2]" means "[required alternatives]" e.g if it is "[alt1|alt2]" you have to choose only 1 of them!
  37. * # This "(alt1|alt2)" means "(not required)" e.g if it is "(alt1|alt2)" you can choose between them!
  38. *
  39. * /chat set [true|false] [time|name|msg|icon] (time|name|msg|icon) (time|name|msg|icon) (time|name|msg|icon)
  40. * /chat [time|name|msg|icon] [true|false]
  41. */
  42.  
  43. /*
  44. * #======================================================================================================================#
  45. * # I'm pretty sure you don't need to change anything below here! It's pretty much fully customizeable in the configs :) #
  46. * #======================================================================================================================#
  47. */
  48.  
  49.  
  50. 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!
  51. var _msg, pmType, timeStamp, _chatCommand = window.chatCommand;
  52. var iconName = ["", "Maxed All Skills", "Master in Mining", "Master in Crafting", "Master in Brewing", "Master in Farming", "Hardcore Account",
  53. "Halloween 2015", "Master in Exploring", "Christmas 2015", "Master in Magic", "Easter Egg", "CO-OP", "Master in Cooking", "Halloween 2016", "Christmas 2016" ];
  54. var iconFile = ["", "icons/stats", "icons/pickaxe", "icons/anvil", "brewing/vialofwater_chat", "icons/watering-can",
  55. "icons/hardcoreIcon", "icons/halloween2015", "icons/archaeology", "sigils/christmas2015", "magic/wizardHatIcon",
  56. "sigils/easter2016", "icons/groupTaskBadge5", "icons/cookingskill", "sigils/halloween2016", "sigils/christmas2016" ];
  57. var rcColours = [
  58. ["#ff0000", "#cc0000", "#b30000"], // Red colors
  59. ["#00cc00", "#009900", "#00e600"], // Green colors
  60. ["#ff99cc", "#ff4da6", "#ff0080"], // Pink colors
  61. ["#9900cc", "#730099", "#bf00ff"], // Purple colors
  62. ["#ff9933", "#ff8000", "#ff9933"], // Orange colors
  63. ["#e6b800", "#cca300", "#b38f00"] /* Gold/Yellow colors */];
  64. var rcColour = -1;
  65. var rcLastColour = -1;
  66. // This is a trigger for the script to make the changes!
  67. window.refreshChat = function(data) {
  68. RainbowChat(data);
  69. };
  70. window.chatCommand = function(cmd) {
  71. var extra = extraCommands(cmd);
  72. if(!extra) _chatCommand(cmd);
  73. };
  74. // Some custom commands to change configs in-game!
  75. function extraCommands(command) {
  76. var cmd = command.substring(1);
  77. var arr = cmd.split(" ");
  78. if(cmd.startsWith("chat")) {
  79. if(arr[2] == "true") {cmd = true;} else if(arr[2] == "false") {cmd = false;} else {return false;}
  80. if(arr[1] == "set") { // Multi changer >>>
  81. if(arr[2] == "true" || arr[2] == "false") {
  82. for(let i = 3; i < arr.length; i++) {
  83. if(arr[i] == "time") { rainbowTime = cmd; }
  84. if(arr[i] == "name") { rainbowName = cmd; }
  85. if(arr[i] == "msg") { rainbowMSG = cmd; }
  86. if(arr[i] == "icon") { removeIcons = cmd; }
  87. }
  88. return true;
  89. }
  90. } // Multi changer <<<
  91. if(arr[2] == "true" || arr[2] == "false") {
  92. if(arr[1] == "time") { rainbowTime = cmd; }
  93. if(arr[1] == "name") { rainbowName = cmd; }
  94. if(arr[1] == "msg") { rainbowMSG = cmd; }
  95. if(arr[1] == "icon") { removeIcons = cmd; }
  96. return true;
  97. }
  98. return true;
  99. }
  100. return false;
  101. }
  102. // The actually magically code is here! This code will make the chat colors change when the above code is triggered and need this code!
  103. // All errors here that Tampermonkey tell you "'someVar' is not defined." is allready in Smitty's scripts!
  104. function RainbowChat(data) {
  105. var chatbox = document.getElementById("chat-area-div");
  106. var splitArray = data.split("~"),
  107. userChatting = splitArray[0],
  108. levelChat = splitArray[1],
  109. tag = splitArray[2],
  110. icon = splitArray[3],
  111. message = splitArray[4],
  112. isPM = splitArray[5];
  113. for (var i = 0; i < mutedPeople.length; i++) { if (mutedPeople[i] == userChatting) return; }
  114. var check = message.split(" ");
  115. for(i = 0; i < check.length; i++) { if(check[i] != "") _msg += check[i] + " "; }
  116. if(_msg == "") return;
  117. var chatSegment = "";
  118. timeStamp = timeFetch();
  119. var totalTextDiv = "";
  120. if ((isPM == 1) || (isPM == 2)) {
  121. if (isPM == 1) { pmType = "PM from"; } else if (isPM == 2) { pmType = "sent PM to"; }
  122. chatSegment = "<span style='color:purple'>" + pmType + " <span style='cursor:pointer;' oncontextmenu='searchPlayerHicores(\"" + userChatting + "\");return false;' onclick='preparePM(\"" + userChatting + "\")'>" + userChatting + "</span>" + ": " + message + "</span><br />";;
  123. lastPMFrom = userChatting;
  124. totalTextDiv = chatbox.innerHTML + timeStamp + chatSegment;
  125. chatbox.innerHTML = totalTextDiv;
  126. if (isAutoScrolling) { $("#chat-area-div").animate({ scrollTop: 55555555 }, 'slow'); }
  127. return;
  128. }
  129. if (isPM == 3) {
  130. chatSegment = "<span style='color:#0066ff;'><span class='chat-tag-yell'>Server Message</span> " + message + " </span><br />";
  131. totalTextDiv = chatbox.innerHTML + timeStamp + chatSegment;
  132. lastPMFrom = userChatting;
  133. chatbox.innerHTML = totalTextDiv;
  134. if (isAutoScrolling) { $("#chat-area-div").animate({ scrollTop: 55555555 }, 'slow'); }
  135. return;
  136. }
  137. if (!removeIcons) {
  138. if (icon >= 1 && icon <= 15) { chatSegment = "<img title='" + iconName[icon] + "' src='images/" + iconFile[icon] + ".png' style='vertical-align: text-top;' width='20' height='20' alt='" + iconName[icon] + "'/>" + chatSegment;}
  139. } // End of "removeIcons"
  140. if (tag == 1) { chatSegment += "<span><img src='images/icons/donor-icon.gif' style='vertical-align: text-top;' width='20' height='20' alt='Donor'/> ";
  141. } else if (tag == 2) { chatSegment += "<span style='color:green;'><span class='chat-tag-contributor'>Contributor</span> ";
  142. } else if (tag == 4) { chatSegment += "<span style='color:#669999;'><span class='chat-tag-mod'>Moderator</span> ";
  143. } else if (tag == 5) { chatSegment += "<span style='color:#666600;'><span class='chat-tag-dev'>Dev</span> "; }
  144. // Random color!
  145. while (rcColour === rcLastColour) { rcColour = getRandomArbitrary(0, rcColours.length); }
  146. rcLastColour = rcColour;
  147. var myColour = rcColours[rcColour][getRandomArbitrary(0, rcColours[rcColour].length)];
  148. if (rainbowName) { chatSegment += "<span style='cursor:pointer;color:" + myColour + "' oncontextmenu='searchPlayerHicores(\"" + userChatting + "\");return false;' onclick='preparePM(\"" + userChatting + "\")'>" + userChatting + " (" + levelChat + "): </span>";
  149. } else { chatSegment += "<span style='cursor:pointer' oncontextmenu='searchPlayerHicores(\"" + userChatting + "\");return false;' onclick='preparePM(\"" + userChatting + "\")'>" + userChatting + " (" + levelChat + "): </span>"; }
  150. //make links clickable
  151. var msg = "";
  152. if (isValidURL(message) && disableUrls == 0) {
  153. var msgArray = message.split(" "), newString = "", linkFound = "";
  154. for (i = 0; i < msgArray.length; i++) {
  155. if (isValidURL(msgArray[i])) {
  156. if (!msgArray[i].startsWith("http")) { linkFound = "<a style='color:#40ff00' href='http://" + msgArray[i] + "' target='_blank'>" + msgArray[i] + "</a>" + " ";
  157. } else { linkFound = "<a style='color:#40ff00' href='" + msgArray[i] + "' target='_blank'>" + msgArray[i] + "</a>" + " "; }
  158. newString += linkFound;
  159. } else { newString += msgArray[i] + " "; }
  160. }
  161. if (rainbowMSG) { chatSegment += "<span style='color:" + myColour + "'>" + newString + "</span>";
  162. } else { chatSegment += newString; }
  163. } else {
  164. if (rainbowMSG) { chatSegment += "<span style='color:" + myColour + "'>" + message + "</span>";
  165. } else { chatSegment += message; }
  166. }
  167. if (rainbowTime) { timeStamp = "<span style='color:" + myColour + "'>" + timeFetch() + "</span>";
  168. } else { timeStamp = timeFetch(); }
  169. totalTextDiv = chatbox.innerHTML + timeStamp + chatSegment + "<span><br />";;
  170. chatbox.innerHTML = totalTextDiv;
  171. if (isAutoScrolling) { $("#chat-area-div").animate({ scrollTop: 55555555 }, 'slow'); }
  172. return data;
  173. }
  174. function getRandomArbitrary(min, max) { return Math.floor(Math.random() * (max - min) + min); }