// ==UserScript==
// @name RainbowChat for DH1
// @namespace http://tampermonkey.net/
// @version 1.2.0
// @description This script is just amazing! Check the script for some configs!
// @author Lasse98brus
// @match http://www.diamondhunt.co/DH1/game.php
// @run-at document-idle
// @grant none
// ==/UserScript==
/* jshint -W097 */
'use strict';
/*
* #=====================================================================================================================================================================================#
* # 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! #
* # 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! #
* # #
* # 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: [email protected] #
* #=====================================================================================================================================================================================#
*/
// Some configs to easily choose the futures that YOU like! :D
var config,
// Here you can just change between "true" and "false" before you login to the game! :)
rainbowTime= false, // Set to "true" to enable rainbow timestamps! (default: "false")
rainbowName= true, // Set to "false" to disable rainbow names! (default: "true")
rainbowMSG = false, // Set to true to enable rainbow messages! (default: "false")
removeIcons= false // Set to "true" to remove all icons in chat, doesn't remove donor icon! (default: "false")
;
/*
* #=================#
* # Update history! #
* #=================#
*
* v1.0.0 - February 19th 2017
* + Initial release! :D
*
* v1.1.0 - March 12th 2017
* + Fixed the "rainbowMSG" to support link!
* + Optimalized the code to be more efficient!
*
* v1.2.0 - March 13th 2017
* + Added some simple commands to change configs in-game!
*
* vx.x.x - Comming soon!
* ? Adding choises of color sets!
* ? Adding more color choises in the config!
*
*/
/*
* #================#
* # Chat Commands! #
* #================#
*
* # This "[alt1|alt2]" means "[required alternatives]" e.g if it is "[alt1|alt2]" you have to choose only 1 of them!
* # This "(alt1|alt2)" means "(not required)" e.g if it is "(alt1|alt2)" you can choose between them!
*
* /chat set [true|false] [time|name|msg|icon] (time|name|msg|icon) (time|name|msg|icon) (time|name|msg|icon)
* /chat [time|name|msg|icon] [true|false]
*/
/*
* #======================================================================================================================#
* # I'm pretty sure you don't need to change anything below here! It's pretty much fully customizeable in the configs :) #
* #======================================================================================================================#
*/
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!
var pmType, timeStamp, _chatCommand = window.chatCommand;
var iconName = ["", "Maxed All Skills", "Master in Mining", "Master in Crafting", "Master in Brewing", "Master in Farming", "Hardcore Account",
"Halloween 2015", "Master in Exploring", "Christmas 2015", "Master in Magic", "Easter Egg", "CO-OP", "Master in Cooking", "Halloween 2016", "Christmas 2016"
];
var iconFile = ["", "icons/stats", "icons/pickaxe", "icons/anvil", "brewing/vialofwater_chat", "icons/watering-can",
"icons/hardcoreIcon", "icons/halloween2015", "icons/archaeology", "sigils/christmas2015", "magic/wizardHatIcon",
"sigils/easter2016", "icons/groupTaskBadge5", "icons/cookingskill", "sigils/halloween2016", "sigils/christmas2016"
];
var rcColours = [
["#ff0000", "#cc0000", "#b30000"], // Red colors
["#00cc00", "#009900", "#00e600"], // Green colors
["#ff99cc", "#ff4da6", "#ff0080"], // Pink colors
["#9900cc", "#730099", "#bf00ff"], // Purple colors
["#ff9933", "#ff8000", "#ff9933"], // Orange colors
["#e6b800", "#cca300", "#b38f00"] // Gold/Yellow colors
];
var rcColour = -1;
var rcLastColour = -1;
// This is a trigger for the script to make the changes!
window.refreshChat = function(data) {
RainbowChat(data);
};
window.chatCommand = function(cmd) {
extraCommands(cmd);
_chatCommand(cmd);
};
// Some custom commands to change configs in-game!
function extraCommands(command) {
var cmd = command.substring(1);
var arr = cmd.split(" ");
if(cmd.startsWith("chat")) {
if(arr[1] == "set") { // Multi changer >>>
if(arr[2] == "true") {
for(let i = 3; i < arr.length; i++) {
if(arr[i] == "time") { rainbowTime=true; }
if(arr[i] == "name") { rainbowName=true; }
if(arr[i] == "msg") { rainbowMSG=true; }
if(arr[i] == "icon") { removeIcons=true; }
}
return;
}
if(arr[2] == "false") {
for(let i = 3; i < arr.length; i++) {
if(arr[i] == "time") { rainbowTime=false; }
if(arr[i] == "name") { rainbowName=false; }
if(arr[i] == "msg") { rainbowMSG=false; }
if(arr[i] == "icon") { removeIcons=false; }
}
return;
}
} // Multi changer <<<
if(arr[1] == "time") {
if(arr[2] == "true") {
rainbowTime=true;
}
if(arr[2] == "false") {
rainbowTime=false;
}
return;
}
if(arr[1] == "name") {
if(arr[2] == "true") {
rainbowName=true;
}
if(arr[2] == "false") {
rainbowName=false;
}
return;
}
if(arr[1] == "msg") {
if(arr[2] == "true") {
rainbowMSG=true;
}
if(arr[2] == "false") {
rainbowMSG=false;
}
return;
}
if(arr[1] == "icon") {
if(arr[2] == "true") {
removeIcons=true;
}
if(arr[2] == "false") {
removeIcons=false;
}
return;
}
return;
}
return;
}
// The actually magically code is here! This code will make the chat colors change when the above code is triggered and need this code!
// All errors here that Tampermonkey tell you "'someVar' is not defined." is allready in Smitty's scripts!
function RainbowChat(data) {
var chatbox = document.getElementById("chat-area-div");
var splitArray = data.split("~"),
userChatting = splitArray[0],
levelChat = splitArray[1],
tag = splitArray[2],
icon = splitArray[3],
message = splitArray[4],
isPM = splitArray[5];
for (var i = 0; i < mutedPeople.length; i++) { if (mutedPeople[i] == userChatting) return; }
var chatSegment = "";
timeStamp = timeFetch();
var totalTextDiv = "";
if ((isPM == 1) || (isPM == 2)) {
if (isPM == 1) { pmType = "PM from"; } else if (isPM == 2) { pmType = "sent PM to"; }
chatSegment = "<span style='color:purple'>" + pmType + " <span style='cursor:pointer;' oncontextmenu='searchPlayerHicores(\"" + userChatting + "\");return false;' onclick='preparePM(\"" + userChatting + "\")'>" + userChatting + "</span>" + ": " + message + "</span><br />";;
lastPMFrom = userChatting;
totalTextDiv = chatbox.innerHTML + timeStamp + chatSegment;
chatbox.innerHTML = totalTextDiv;
if (isAutoScrolling) { $("#chat-area-div").animate({ scrollTop: 55555555 }, 'slow'); }
return;
}
if (isPM == 3) {
chatSegment = "<span style='color:#0066ff;'><span class='chat-tag-yell'>Server Message</span> " + message + " </span><br />";
totalTextDiv = chatbox.innerHTML + timeStamp + chatSegment;
lastPMFrom = userChatting;
chatbox.innerHTML = totalTextDiv;
if (isAutoScrolling) { $("#chat-area-div").animate({ scrollTop: 55555555 }, 'slow'); }
return;
}
if (!removeIcons) {
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;
}
} // End of "removeIcons"
if (tag == 1) {
chatSegment += "<span><img src='images/icons/donor-icon.gif' style='vertical-align: text-top;' width='20' height='20' alt='Donor'/> ";
} else if (tag == 2) {
chatSegment += "<span style='color:green;'><span class='chat-tag-contributor'>Contributor</span> ";
} else if (tag == 4) {
chatSegment += "<span style='color:#669999;'><span class='chat-tag-mod'>Moderator</span> ";
} else if (tag == 5) { chatSegment += "<span style='color:#666600;'><span class='chat-tag-dev'>Dev</span> "; }
// Random color!
while (rcColour === rcLastColour) { rcColour = getRandomArbitrary(0, rcColours.length); }
rcLastColour = rcColour;
var myColour = rcColours[rcColour][getRandomArbitrary(0, rcColours[rcColour].length)];
if (rainbowName) {
chatSegment += "<span style='cursor:pointer;color:" + myColour + "' oncontextmenu='searchPlayerHicores(\"" + userChatting + "\");return false;' onclick='preparePM(\"" + userChatting + "\")'>" + userChatting + " (" + levelChat + "): </span>";
} else { chatSegment += "<span style='cursor:pointer' oncontextmenu='searchPlayerHicores(\"" + userChatting + "\");return false;' onclick='preparePM(\"" + userChatting + "\")'>" + userChatting + " (" + levelChat + "): </span>"; }
//make links clickable
var msg = "";
if (isValidURL(message) && disableUrls == 0) {
var msgArray = message.split(" ");
var newString = "";
var linkFound = "";
for (i = 0; i < msgArray.length; i++) {
if (isValidURL(msgArray[i])) {
if (!msgArray[i].startsWith("http")) {
linkFound = "<a style='color:#40ff00' href='http://" + msgArray[i] + "' target='_blank'>" + msgArray[i] + "</a>" + " ";
} else {
linkFound = "<a style='color:#40ff00' href='" + msgArray[i] + "' target='_blank'>" + msgArray[i] + "</a>" + " ";
}
newString += linkFound;
} else {
newString += msgArray[i] + " ";
}
}
if (rainbowMSG) {
chatSegment += "<span style='color:" + myColour + "'>" + newString + "</span>";
} else {
chatSegment += newString;
}
} else {
if (rainbowMSG) {
chatSegment += "<span style='color:" + myColour + "'>" + message + "</span>";
} else {
chatSegment += message;
}
}
if (rainbowTime) {
timeStamp = "<span style='color:" + myColour + "'>" + timeFetch() + "</span>";
} else {
timeStamp = timeFetch();
}
chatSegment += "<span><br />";
totalTextDiv = chatbox.innerHTML + timeStamp + chatSegment;
chatbox.innerHTML = totalTextDiv;
if (isAutoScrolling) { $("#chat-area-div").animate({ scrollTop: 55555555 }, 'slow'); }
return data;
}
function getRandomArbitrary(min, max) {
return Math.floor(Math.random() * (max - min) + min);
}