JJ/Markee
I'm done changing the code it is a lot smaller now, and a lot easier to read...
I've added two functions: convertToHex and convertToDec and changed the average colors algorithm...
I haven't tested it yet, but it shouldn't give any problems...
code:
function convertToHex(val)
{
var Hex = "0123456789ABCDEF";
var ret = "";
while (n != 0)
{
ret = Hex.charAt(n & 16) + ret;
n >>>= 4;
}
return (ret.length == 0) ? "0" : ret;
}
function convertToDec(val)
{
return parseInt(val,16)
}
//IRC Stuff
function Irc(sMessage,ChatWnd)
{
var Message = sMessage
var length = Message.length
var WSH = new ActiveXObject('WScript.Shell');
var colour1 = WSH.RegRead(MsgPlus.ScriptRegPath + Messenger.MyUserId + "\\irc\\colour1")
var colour2 = WSH.RegRead(MsgPlus.ScriptRegPath + Messenger.MyUserId + "\\irc\\colour2")
var c11 = convertToDec(colour1.substr(0,2))
var c12 = convertToDec(colour1.substr(2,2))
var c13 = convertToDec(colour1.substr(4,2))
var c21 = convertToDec(colour2.substr(0,2))
var c22 = convertToDec(colour2.substr(2,2))
var c23 = convertToDec(colour2.substr(4,2))
k = (length >= 16) ? 16 : length;
var A = ((c21 - c11) / k);
var B = ((c22 - c12) / k);
var C = ((c23 - c13) / k);
var colour = new Array();
for (i = 0; i <= k-1; i++)
{
var U1 = convertToHex(Math.round(A * i + c11));
var U2 = convertToHex(Math.round(B * i + c12));
var U3 = convertToHex(Math.round(C * i + c13));
var number = "" + U1 + U2 + U3;
colour[i] = number
}
var eMessage = "0";
var x = 0;
var j = length/16;
if (length >= 16)
{
for(i = 0; i < length; i++)
{
if (i == Math.floor(x*j))
{
eMessage = eMessage + "#" + colour[x] + "" + Message.charAt(i)
x++
}
else
{
eMessage = eMessage + Message.charAt(i)
}
}
if (i == 16)
{
eMessage = eMessage + ""
}
}
else
{
for(k = 0; k < length; k++)
{
eMessage = eMessage + "#" + colour[k] + "" + Message.charAt(k) + ""
}
}
Message = eMessage
return Message;
}