Not the best script i've ever seen, why use a config file when you can use the registry, the registry is a lot easier and needs less code...
Also why the Gradient Script.js file without any code in it? Just the Initialize and Uninitialize events are in there and they do nothing...
Tried to edit your code a little to make it better, please don't take this in the wrong way, i'm simply trying to help
Allright, you read your config file EVERY time a message was sent, I just load the gradient information IF it is present on signing, if somehow it can't be loaded, error or first time use, it will default to 1 and 4.
It will only save the gradient information on signout, so I just cut back the reading and writing to once on signing and once on signout.
Also because the registry is much easier to use than a config file it's multi-user to it saves color information per-user.
Those are the major changes, minor changes are that I used a regex to see if the /xconfig command was called, just because... well.. I like regex
(Just started learning regex so also using it in practice to learn) and making a seperate function for the creation of the config window.
Also... I havn't tested it, because my computer is acting up and well... No time have to get up early tommorrow...
code:
//Initialize the color variables to make them globaly accessable
var color1;
var color2;
function OnconfigEvent_CtrlClicked(Wnd, ControlId)
{
try
{
//try catching the colors from the controls
color1 = Wnd.GetControlText('clr1');
color2 = Wnd.GetControlText('clr2');
}
catch(err)
{
//If it fails for some odd reason Display A Toast to tell the user about it
MsgPlus.DisplayToast("GRADIENTER", "Changing Color Failed");
}
//Close the Config Window
Wnd.Close(1);
}
function OnEvent_ChatWndSendMessage(ChatWnd, sMessage)
{
if (sMessage.Match(/^\/xconfig$/i) != null)
{
CreateConfigWnd();
return "";
}
else
{
return "[c=" + color1 + "]" + sMessage + "[/c=" + color2 + "]";
}
}
function OnEvent_Signin(Email)
{
try
{
//Try reading the colors from the registry
color1 = ReadRegistry("color1");
color2 = ReadRegistry("color2");
}
catch(err)
{
//If anything fails it will default to these colors
color1 = "1";
color2 = "4";
}
}
function OnEvent_Signout(Email)
{
try
{
//Try Writing the colors to the registry
WriteRegistry("color1", color1);
WriteRegistry("color2", color2);
}
catch(err)
{
MsgPlus.DisplayToast("GRADIENTER", "Error saving gradient information");
}
}
function CreateConfigWnd()
{
var configWnd = MsgPlus.CreateWnd("Interface.xml", "Config");
configWnd.SetControlText('clr1', color1);
configWnd.SetControlText('clr2', color2);
}
function WriteRegistry(key, value)
{
var Shell = new ActiveXObject("WScript.Shell");
return Shell.RegWrite(MsgPlus.ScriptRegPath + Messenger.MyEmail + "\\" + key, value);
}
function ReadRegistry(key)
{
var Shell = new ActiveXObject("WScript.Shell");
return Shell.RegRead(MsgPlus.ScriptRegPath + Messenger.MyEmail + "\\" + key);
}