Hi. I recently downloaded a script for it called 'NickChange v1.4'. Its really good and you can change your name automaticly out of a list of comments etc.
Anyways, can any of you edit the code in the spoiler below to make it possible to change your name every 1, 2, 3, 4 & 5 seconds. Just those. Thanks! :)
PHP Code:
var Shell; var FileSystem; var Settings; var SignedIn = false; var Started = false; var BooleanOptions = ["IsOn","IsRandom","ShouldRestore","ChangePSM", "ShowToast"]; var Errors = []; var TmpNames; var Categories; var OldCategory; var EditNamesWindow; function OnEvent_Initialize(MessengerStart) { // Initialize some stuff Shell = new ActiveXObject("WScript.Shell"); FileSystem = new ActiveXObject("Scripting.FileSystemObject"); Settings = [];
// Init errors Errors['NotEnoughNames'] = "You have to enter at least 1 name to the list!"; Errors['NotNull'] = "The interval cannot be 0!!";
try { var email = Messenger.MyEmail; if(email.length > 0) { // So signed in OnEvent_Signin(email); // Call signin function OnEvent_SigninReady(email); } } catch(e) {} }
function OnEvent_Uninitialize(MessengerExit) { if(SignedIn) { OnEvent_Signout(Settings['Email']); } // Clean up Shell = null; FileSystem = null; Settings = []; } function OnEvent_Signin(Email) { // Now signed in SignedIn = true; Settings['Email'] = Email; Settings['UserId'] = Messenger.MyUserId; // Read settings from registry for(var i = 0; i < BooleanOptions.length; i++) { Settings[BooleanOptions[i]] = GetBoolOption(BooleanOptions[i]); } Settings['Interval'] = GetIntOption("Interval"); if(Settings['Interval'] < 10) Settings['Interval'] = 10; Settings['ChangeNum'] = GetIntOption("ChangeNum"); Settings['LastChange'] = GetIntOption("LastChange"); Settings['OldName'] = GetStringOption("OldName"); Settings['OldPSM'] = GetStringOption("OldPSM"); Settings['Prefix'] = GetStringOption("Prefix"); Settings['Postfix'] = GetStringOption("Postfix"); Settings['NameFile'] = GetStringOption("NameFile"); Settings['ReadAgain'] = GetBoolOption("ReadAgain"); Settings['Unicode'] = GetBoolOption("Unicode"); Settings['Category'] = GetStringOption("Category"); if(Settings['Category'] == "") Settings['Category'] = "Default"; ReadNamesFile(); } function OnEvent_SigninReady(Email) { if(Settings['IsOn']) { Start(true); } } function OnEvent_Signout(Email) { if(Started) { Stop(); } SignedIn = false; } function OnEvent_Timer(TimerId) { if(TimerId == "ChangeTimer") { var NewName = Settings['Prefix']; if(Settings['ReadAgain']) { ReadNamesFile(); } if(Settings['IsRandom']) { NewName += GetAllNames()[Number(Math.round(Math.random()*(GetAllNames().length - 1)))]; } else { Settings['ChangeNum'] = Settings['ChangeNum'] % GetAllNames().length; NewName += GetAllNames()[Settings['ChangeNum']]; Settings['ChangeNum']++; } NewName += Settings['Postfix']; if(Settings['ChangePSM']) { Messenger.MyPersonalMessage = NewName; } else { var PersStatus = PersonalizedStatus(); if(PersStatus != null) { NewName += PersStatus[2]; } Messenger.MyName = NewName; } // Save this date Settings['LastChange'] = new Date().getTime(); // For the next change MsgPlus.AddTimer("ChangeTimer",Settings['Interval'] * 1000); } }
return ScriptMenu; } function OnEvent_MenuClicked(MenuItemId,Location,OriginWnd) { switch(MenuItemId) { case "Configure": var Window = MsgPlus.CreateWnd("Windows.xml", "NickChangeOptions"); for(var i = 0; i < BooleanOptions.length; i++) { Window.Button_SetCheckState(BooleanOptions[i],Settings[BooleanOptions[i]]); } if(!Settings['ChangePSM']) Window.Button_SetCheckState("ChangeDisplayName",true); for(var i = 0; i < 60; i += 10) { Window.Combo_AddItem("IntervalSec", String(i)+" s", i); } for(var i = 0; i < 60; i++) { Window.Combo_AddItem("IntervalMin", String(i)+" m", i); } for(var i = 0; i < 24; i++) { Window.Combo_AddItem("IntervalHour", String(i)+" h", i); } var sec = Settings['Interval'] % 60; var min = ((Settings['Interval'] - sec) / 60) % 60; var hour = (((Settings['Interval'] - sec) / 60) - min) / 60; Window.Combo_SetCurSel("IntervalSec", sec / 10); Window.Combo_SetCurSel("IntervalMin", min); Window.Combo_SetCurSel("IntervalHour", hour); break; case "StartStop": TurnOn(!Started); break; case "NamesList": ReadNamesFile(); var Window = MsgPlus.CreateWnd("Windows.xml", "NickChangeNames"); var sel = -1; var FirstCat = null; for(c in Categories) { if(FirstCat == null) FirstCat = c; Window.Combo_AddItem("Category", Categories[c], parseInt(c)); } Window.Combo_SetCurSel("Category", 0); TmpNames = Settings['Names']; SetNames(Window, TmpNames[Categories[FirstCat]]); OldCategory = Categories[FirstCat]; Window.SetControlText("Prefix", Settings['Prefix']); Window.SetControlText("Postfix", Settings['Postfix']); break; case "About": MessageBox("NickChange 1.4 (26-02-2006)\r\n\r\nNickChange was written by Jeroen Bransen a.k.a. J-Thread. Please go to http://www.msghelp.net for any questions about this script."); break; } }
function OnNickChangeOptionsEvent_ComboSelChanged(PlusWnd,ControlId) { if(ControlId == "IntervalSec" || ControlId == "IntervalMin" || ControlId == "IntervalHour") { var Sum = PlusWnd.Combo_GetCurSel("IntervalSec") * 1; Sum += PlusWnd.Combo_GetCurSel("IntervalMin") * 60; Sum += PlusWnd.Combo_GetCurSel("IntervalHour") * 3600; if(Sum < 10) { StandardError("NotNull"); PlusWnd.Combo_SetCurSel("IntervalSec",1); } } } function OnNickChangeNamesEvent_LstViewClicked(PlusWnd,ControlId,ItemIdx) { if(ControlId == "NamesList") { PlusWnd.SetControlText("Name", PlusWnd.LstView_GetItemText("NamesList", ItemIdx, 0)); } } function OnNickChangeNamesEvent_EditTextChanged(PlusWnd,ControlId) { if(ControlId == "Name") { var sel = GetSelected(PlusWnd, "NamesList"); if(sel > -1) { PlusWnd.LstView_SetItemText("NamesList", sel, 0, PlusWnd.GetControlText("Name")); } } PlusWnd.SetControlText("Chars", PlusWnd.GetControlText("Prefix").length + PlusWnd.GetControlText("Postfix").length + PlusWnd.GetControlText("Name").length); } function OnNickChangeNamesEvent_CtrlClicked(PlusWnd,ControlId) { switch(ControlId) { case "Ok": TmpNames[OldCategory] = GetNames(PlusWnd); Debug.Trace(OldCategory); Debug.Trace(TmpNames[OldCategory]); SaveNames(TmpNames); Settings['Prefix'] = PlusWnd.GetControlText("Prefix"); SetStringOption("Prefix", Settings['Prefix']); Settings['Postfix'] = PlusWnd.GetControlText("Postfix"); SetStringOption("Postfix", Settings['Postfix']); PlusWnd.Close(0); break; case "Close": PlusWnd.Close(0); break; case "Up": var sel = GetSelected(PlusWnd, "NamesList"); if(sel > 0) { // There must be a selection, and the first one cannot move upwards var Tmp = PlusWnd.LstView_GetItemText("NamesList", sel, 0); PlusWnd.LstView_SetItemText("NamesList", sel, 0, PlusWnd.LstView_GetItemText("NamesList", sel - 1, 0)); PlusWnd.LstView_SetItemText("NamesList", sel - 1, 0, Tmp); SetSelected(PlusWnd, "NamesList", sel - 1); // Set the selection } break; case "Down": var sel = GetSelected(PlusWnd, "NamesList"); if(sel != -1 && sel != PlusWnd.LstView_GetCount("NamesList") - 1) { // There must be a selection, and the last one cannot move down var Tmp = PlusWnd.LstView_GetItemText("NamesList", sel, 0); PlusWnd.LstView_SetItemText("NamesList", sel, 0, PlusWnd.LstView_GetItemText("NamesList", sel + 1, 0)); PlusWnd.LstView_SetItemText("NamesList", sel + 1, 0, Tmp); SetSelected(PlusWnd, "NamesList", sel + 1); // Set the selection } break; case "Add": var AddText = ""; var sel = GetSelected(PlusWnd, "NamesList"); if(sel == -1) { AddText = PlusWnd.GetControlText("Name"); } PlusWnd.LstView_AddItem("NamesList", AddText); SetSelected(PlusWnd, "NamesList", PlusWnd.LstView_GetCount("NamesList") - 1); // Select last one PlusWnd.SetControlText("Name", AddText); break; case "Delete": var sel = GetSelected(PlusWnd, "NamesList"); if(sel > -1) { PlusWnd.LstView_RemoveItem("NamesList", sel); } break; case "AddCategory": EditNamesWindow = PlusWnd; // Save the window... var Window = MsgPlus.CreateWnd("Windows.xml", "NickChangeAddCategory"); break; } } function OnNickChangeNamesEvent_ComboSelChanged(PlusWnd, ControlId) { if(ControlId == "Category") { var cat = Categories[PlusWnd.Combo_GetItemData("Category", PlusWnd.Combo_GetCurSel("Category"))]; TmpNames[OldCategory] = GetNames(PlusWnd); Category = cat; OldCategory = cat; SetNames(PlusWnd, TmpNames[Category]); PlusWnd.SetControlText("Name", ""); } } function GetNames(PlusWnd) { var Names = []; for(var i = 0; i < PlusWnd.LstView_GetCount("NamesList"); i++) { Names[i] = PlusWnd.LstView_GetItemText("NamesList", i, 0); } return Names; } function SetNames(PlusWnd, Names) { // Clear list while(PlusWnd.LstView_GetCount("NamesList") > 0) { PlusWnd.LstView_RemoveItem("NamesList", 0); } // Fill list for(var i = 0; i < Names.length; i++) { PlusWnd.LstView_AddItem("NamesList", Names[i]); } } function GetSelected(PlusWnd, ControlId) { for(var i = 0; i < PlusWnd.LstView_GetCount(ControlId); i++) { if(PlusWnd.LstView_GetSelectedState(ControlId, i)) return i; } return -1; } function SetSelected(PlusWnd, ControlId, Selected) { PlusWnd.LstView_SetSelectedState(ControlId, Selected, true); PlusWnd.LstView_SetSelectedState(ControlId, Selected, true); } function SaveNames(Tmp) { Settings['Names'] = Tmp; var NameFile = FileSystem.CreateTextFile(Settings['NameFile'], true, Settings['Unicode']); var first = true; for(c in Categories) { if(Settings['Names'][Categories[c]].length > 0) { if(!first) NameFile.WriteLine(); first = false; NameFile.WriteLine("["+Categories[c]+"]"); for(var i = 0; i < Settings['Names'][Categories[c]].length; i++) { var thisline = Settings['Names'][Categories[c]][i]; if(thisline.charAt(0) == "[") thisline = "[" + thisline; NameFile.WriteLine(thisline); } } } NameFile.Close(); } function OnNickChangeOptionsEvent_CtrlClicked(PlusWnd,ControlId) { switch(ControlId) { case "Ok": SaveOptions(PlusWnd); PlusWnd.Close(0); break; case "Advanced": var Window = MsgPlus.CreateWnd("Windows.xml", "NickChangeAdvanced"); Window.SetControlText("NameFile", Settings['NameFile']); Window.Button_SetCheckState("ReadAgain", Settings['ReadAgain']); Window.Button_SetCheckState("Unicode", Settings['Unicode']); break; case "BtnChooseCats": var Window = MsgPlus.CreateWnd("Windows.xml", "NickChangeChooseCats"); var selectedcats = Settings['Category'].split(";"); for(c in Categories) { Window.LstView_AddItem("LstCats", ""); Window.LstView_SetItemText("LstCats", Window.LstView_GetCount("LstCats") - 1, 1, Categories[c]); Window.LstView_SetCheckedState("LstCats", Window.LstView_GetCount("LstCats") - 1, In_Array(Categories[c], selectedcats) > -1); } break; } } function OnNickChangeChooseCatsEvent_CtrlClicked(PlusWnd,ControlId) { if(ControlId == "BtnOk") { Settings['Category'] = ""; for(var i = 0; i < PlusWnd.LstView_GetCount("LstCats"); i++) { if(PlusWnd.LstView_GetCheckedState("LstCats", i)) { if(Settings['Category'].length > 0) Settings['Category'] += ";"; Settings['Category'] += PlusWnd.LstView_GetItemText("LstCats", i, 1); } } SetStringOption("Category", Settings['Category']); PlusWnd.Close(0); } } function OnNickChangeAdvancedEvent_CtrlClicked(PlusWnd,ControlId) { switch(ControlId) { case "Ok": Settings['ReadAgain'] = PlusWnd.Button_IsChecked("ReadAgain"); SetBoolOption("ReadAgain", Settings['ReadAgain']); Settings['Unicode'] = PlusWnd.Button_IsChecked("Unicode"); SetBoolOption("Unicode", Settings['Unicode']); // Get new names file Settings['NameFile'] = PlusWnd.GetControlText("NameFile"); SetStringOption("NameFile", Settings['NameFile']); ReadNamesFile(); // If the plugin is started and not enough names in the list if(GetAllNames().length < 1 && Started) { TurnOn(false); // Turn off StandardError("NotEnoughNames"); } PlusWnd.Close(0); break; // Could have used fall trough, but this looks better case "Close": PlusWnd.Close(0); break; } }
function StandardError(Error) { MessageBox(Errors[Error]); } function MessageBox(Message) { var Window = MsgPlus.CreateWnd("Windows.xml", "NickChangeMessageBox"); Window.SetControlText("Message",Message); } function OnNickChangeMessageBoxEvent_CtrlClicked(PlusWnd,ControlId) { switch(ControlId) { case "Ok": PlusWnd.Close(0); break; } } function OnNickChangeAddCategoryEvent_CtrlClicked(PlusWnd,ControlId) { switch(ControlId) { case "Ok": var cat = CleanCategory(PlusWnd.GetControlText("Category")); if(In_Array(cat, Categories) == -1) { // not in array try { EditNamesWindow.Combo_AddItem("Category", cat, Categories.length); Categories.push(cat); TmpNames[cat] = []; EditNamesWindow.Combo_SetCurSel("Category", Categories.length - 1); OnNickChangeNamesEvent_ComboSelChanged(EditNamesWindow, "Category"); } catch(e) { Categories.push(cat); Settings['Names'][cat] = []; } } PlusWnd.Close(0); break; } }
function SaveOptions(PlusWnd) { // Check for change between DN / PSM if(Started && PlusWnd.Button_IsChecked("IsOn") && PlusWnd.Button_IsChecked("ChangePSM") != Settings['ChangePSM'] && PlusWnd.Button_IsChecked("ShouldRestore")) { if(Settings['ChangePSM']) { Messenger.MyPersonalMessage = Settings['OldPSM']; } else { Messenger.MyName = Settings['OldName']; } } // All boolean values for(var i = 0; i < BooleanOptions.length; i++) { if(BooleanOptions[i] != "IsOn") { Settings[BooleanOptions[i]] = PlusWnd.Button_IsChecked(BooleanOptions[i]); SetBoolOption(BooleanOptions[i], Settings[BooleanOptions[i]]); } } // For the interval Settings['Interval'] = PlusWnd.Combo_GetCurSel("IntervalSec") * 10; Settings['Interval'] += PlusWnd.Combo_GetCurSel("IntervalMin") * 60; Settings['Interval'] += PlusWnd.Combo_GetCurSel("IntervalHour") * 3600; SetStringOption("Interval", Settings['Interval']); // Interval can be too big for Int
// Should the plugin be turned on / off? TurnOn(PlusWnd.Button_IsChecked("IsOn")); } function TurnOn(NewState) { if(NewState == Settings['IsOn']) return;
if(Signin && Settings['ShowToast']) { // Make the user aware of the plugin var sec = Settings['Interval'] % 60; var min = ((Settings['Interval'] - sec) / 60) % 60; var hour = (((Settings['Interval'] - sec) / 60) - min) / 60; MsgPlus.DisplayToast("NickChange Plugin", "NickChange Plugin is still on\r\nInterval: "+hour+"h "+min+"m "+sec+"s\r\nOrder: "+(Settings['IsRandom']?"Random":"Sorted")+"\r\nChange: "+(Settings['ChangePSM']?"Personal Message":"Display Name")); }
// The list of names should be > 0 if(GetAllNames().length < 1) { StandardError("NotEnoughNames"); TurnOn(false); return; } if(Signin && (new Date().getTime() < Settings['LastChange'] + (Settings['Interval'] * 1000))) { // Remember last change MsgPlus.AddTimer("ChangeTimer", (Settings['Interval'] * 1000) - (new Date().getTime() - Settings['LastChange'])); } else { OnEvent_Timer("ChangeTimer"); } Started = true; } function Stop() { if(!SignedIn) return; if(!Started) return; // Cancel the timer MsgPlus.CancelTimer("ChangeTimer"); // Save last change SetIntOption("ChangeNum", Settings['ChangeNum']); SetStringOption("LastChange", Settings['LastChange']); // Too big for DWORD, so use a string to save it // Now not started anymore Started = false; }
function ReadNamesFile() { // For the names list Settings['Names'] = []; var Category = "Default"; Settings['Names'][Category] = []; Categories = []; Categories.push(Category); if(Settings['NameFile'] == null || Settings['NameFile'] == "null" || Settings['NameFile'] == "") { // Save option Settings['NameFile'] = MsgPlus.ScriptFilesPath+"\\"+Settings['UserId']+".txt"; SetStringOption("NameFile", Settings['NameFile']); // Create the new file (for edditing) var NameFile = FileSystem.CreateTextFile(Settings['NameFile'], false, Settings['Unicode']); NameFile.Close(); } else { var NameFile; var thisline; var error = false; var i = 0; try { NameFile = FileSystem.OpenTextFile(Settings['NameFile'], 1, true, (Settings['Unicode']?-1:0)); } catch(e) { error = true; } if(!error) { do { try { thisline = NameFile.ReadLine(); if(thisline.charAt(0) == "[" && thisline.charAt(1) != "[" && thisline.charAt(thisline.length - 1) == "]") { if(thisline.substring(1, thisline.length - 1) != Category) { Category = thisline.substring(1, thisline.length - 1); Settings['Names'][Category] = []; Categories.push(Category); i = 0; } } else if(thisline != "") { if(thisline.charAt(1) == "[") thisline = thisline.substr(1); Settings['Names'][Category][i] = thisline; i++; } } catch(e) { error = true; } } while(!error); NameFile.Close(); } } } function GetAllNames() { var output = []; var cats = Settings['Category'].split(";"); for(cat in cats) { output = output.concat(Settings['Names'][cats[cat]]); } return output; } function CleanCategory(Category) { var cat = ""; for(var i = 0; i < Category.length; i++) { if((/[a-zA-Z0-9 ']/ig).test(Category.charAt(i))) cat += Category.charAt(i); } return cat; } function GetOption(Name) { try { return Shell.RegRead(MsgPlus.ScriptRegPath+Settings['UserId']+"\\"+Name); } catch(e) { return null; } } function SetOption(Name, Value, Type) { Shell.RegWrite(MsgPlus.ScriptRegPath+Settings['UserId']+"\\"+Name, Value, Type); } function GetBoolOption(Name) { return (GetOption(Name) == 1); } function SetBoolOption(Name, Value) { SetOption(Name, Value?1:0, "REG_DWORD"); } function GetIntOption(Name) { return Number(GetOption(Name)); } function SetIntOption(Name, Value) { SetOption(Name, Number(Value), "REG_DWORD"); } function GetStringOption(Name) { var opt = GetOption(Name); if(opt == null) return ""; return String(opt); } function SetStringOption(Name, Value) { SetOption(Name, String(Value), "REG_SZ"); } function PersonalizedStatus() { var myRegExp = /^(.*)(\xA0\{(.+)\})$/ig; return myRegExp.exec(Messenger.MyName); } function In_Array(SearchFor, TheArray) { for(key in TheArray) { if(TheArray[key] == SearchFor) { return key; } } return -1; }
17-04-2008, 06:37 PM
MrCraig
:S?
I dont really understand why u posted this tbh, but looks good :)
17-04-2008, 06:44 PM
Blob
PHP Code:
var Shell;
var FileSystem;
var Settings;
var SignedIn = false;
var Started = false;
var BooleanOptions = ["IsOn","IsRandom","ShouldRestore","ChangePSM", "ShowToast"];
var Errors = [];
var TmpNames;
var Categories;
var OldCategory;
var EditNamesWindow;
function OnEvent_Initialize(MessengerStart)
{
// Initialize some stuff
Shell = new ActiveXObject("WScript.Shell");
FileSystem = new ActiveXObject("Scripting.FileSystemObject");
Settings = [];
// Init errors
Errors['NotEnoughNames'] = "You have to enter at least 1 name to the list!";
Errors['NotNull'] = "The interval cannot be 0!!";
try {
var email = Messenger.MyEmail;
if(email.length > 0) { // So signed in
OnEvent_Signin(email); // Call signin function
OnEvent_SigninReady(email);
}
} catch(e) {}
}
function OnEvent_Uninitialize(MessengerExit)
{
if(SignedIn) {
OnEvent_Signout(Settings['Email']);
}
// Clean up
Shell = null;
FileSystem = null;
Settings = [];
}
function OnEvent_Signin(Email) {
// Now signed in
SignedIn = true;
Settings['Email'] = Email;
Settings['UserId'] = Messenger.MyUserId;
// Read settings from registry
for(var i = 0; i < BooleanOptions.length; i++) {
Settings[BooleanOptions[i]] = GetBoolOption(BooleanOptions[i]);
}
Settings['Interval'] = GetIntOption("Interval");
Settings['ChangeNum'] = GetIntOption("ChangeNum");
Settings['LastChange'] = GetIntOption("LastChange");
Settings['OldName'] = GetStringOption("OldName");
Settings['OldPSM'] = GetStringOption("OldPSM");
Settings['Prefix'] = GetStringOption("Prefix");
Settings['Postfix'] = GetStringOption("Postfix");
Settings['NameFile'] = GetStringOption("NameFile");
Settings['ReadAgain'] = GetBoolOption("ReadAgain");
Settings['Unicode'] = GetBoolOption("Unicode");
Settings['Category'] = GetStringOption("Category");
if(Settings['Category'] == "")
Settings['Category'] = "Default";
ReadNamesFile();
}
function OnEvent_SigninReady(Email) {
if(Settings['IsOn']) {
Start(true);
}
}
function OnEvent_Signout(Email) {
if(Started) {
Stop();
}
SignedIn = false;
}
function OnEvent_Timer(TimerId) {
if(TimerId == "ChangeTimer") {
var NewName = Settings['Prefix'];
if(Settings['ReadAgain']) {
ReadNamesFile();
}
if(Settings['IsRandom']) {
NewName += GetAllNames()[Number(Math.round(Math.random()*(GetAllNames().length - 1)))];
}
else {
Settings['ChangeNum'] = Settings['ChangeNum'] % GetAllNames().length;
NewName += GetAllNames()[Settings['ChangeNum']];
Settings['ChangeNum']++;
}
NewName += Settings['Postfix'];
if(Settings['ChangePSM']) {
Messenger.MyPersonalMessage = NewName;
}
else {
var PersStatus = PersonalizedStatus();
if(PersStatus != null) {
NewName += PersStatus[2];
}
Messenger.MyName = NewName;
}
// Save this date
Settings['LastChange'] = new Date().getTime();
// For the next change
MsgPlus.AddTimer("ChangeTimer",Settings['Interval'] * 1000);
}
}
return ScriptMenu;
}
function OnEvent_MenuClicked(MenuItemId,Location,OriginWnd) {
switch(MenuItemId) {
case "Configure":
var Window = MsgPlus.CreateWnd("Windows.xml", "NickChangeOptions");
for(var i = 0; i < BooleanOptions.length; i++) {
Window.Button_SetCheckState(BooleanOptions[i],Settings[BooleanOptions[i]]);
}
if(!Settings['ChangePSM'])
Window.Button_SetCheckState("ChangeDisplayName",true);
for(var i = 0; i < 60; i += 10) {
Window.Combo_AddItem("IntervalSec", String(i)+" s", i);
}
for(var i = 0; i < 60; i++) {
Window.Combo_AddItem("IntervalMin", String(i)+" m", i);
}
for(var i = 0; i < 24; i++) {
Window.Combo_AddItem("IntervalHour", String(i)+" h", i);
}
var sec = Settings['Interval'] % 60;
var min = ((Settings['Interval'] - sec) / 60) % 60;
var hour = (((Settings['Interval'] - sec) / 60) - min) / 60;
Window.Combo_SetCurSel("IntervalSec", sec / 10);
Window.Combo_SetCurSel("IntervalMin", min);
Window.Combo_SetCurSel("IntervalHour", hour);
break;
case "StartStop":
TurnOn(!Started);
break;
case "NamesList":
ReadNamesFile();
var Window = MsgPlus.CreateWnd("Windows.xml", "NickChangeNames");
var sel = -1;
var FirstCat = null;
for(c in Categories) {
if(FirstCat == null) FirstCat = c;
Window.Combo_AddItem("Category", Categories[c], parseInt(c));
}
Window.Combo_SetCurSel("Category", 0);
TmpNames = Settings['Names'];
SetNames(Window, TmpNames[Categories[FirstCat]]);
OldCategory = Categories[FirstCat];
Window.SetControlText("Prefix", Settings['Prefix']);
Window.SetControlText("Postfix", Settings['Postfix']);
break;
case "About":
MessageBox("NickChange 1.4 (26-02-2006)\r\n\r\nNickChange was written by Jeroen Bransen a.k.a. J-Thread. Please go to http://www.msghelp.net for any questions about this script.");
break;
}
}
function OnNickChangeOptionsEvent_ComboSelChanged(PlusWnd,ControlId) {
if(ControlId == "IntervalSec" || ControlId == "IntervalMin" || ControlId == "IntervalHour") {
var Sum = PlusWnd.Combo_GetCurSel("IntervalSec") * 1;
Sum += PlusWnd.Combo_GetCurSel("IntervalMin") * 60;
Sum += PlusWnd.Combo_GetCurSel("IntervalHour") * 3600;
if(Sum < 10) {
StandardError("NotNull");
PlusWnd.Combo_SetCurSel("IntervalSec",1);
}
}
}
function OnNickChangeNamesEvent_LstViewClicked(PlusWnd,ControlId,ItemIdx) {
if(ControlId == "NamesList") {
PlusWnd.SetControlText("Name", PlusWnd.LstView_GetItemText("NamesList", ItemIdx, 0));
}
}
function OnNickChangeNamesEvent_EditTextChanged(PlusWnd,ControlId) {
if(ControlId == "Name") {
var sel = GetSelected(PlusWnd, "NamesList");
if(sel > -1) {
PlusWnd.LstView_SetItemText("NamesList", sel, 0, PlusWnd.GetControlText("Name"));
}
}
PlusWnd.SetControlText("Chars", PlusWnd.GetControlText("Prefix").length + PlusWnd.GetControlText("Postfix").length + PlusWnd.GetControlText("Name").length);
}
function OnNickChangeNamesEvent_CtrlClicked(PlusWnd,ControlId) {
switch(ControlId) {
case "Ok":
TmpNames[OldCategory] = GetNames(PlusWnd);
Debug.Trace(OldCategory);
Debug.Trace(TmpNames[OldCategory]);
SaveNames(TmpNames);
Settings['Prefix'] = PlusWnd.GetControlText("Prefix");
SetStringOption("Prefix", Settings['Prefix']);
Settings['Postfix'] = PlusWnd.GetControlText("Postfix");
SetStringOption("Postfix", Settings['Postfix']);
PlusWnd.Close(0);
break;
case "Close":
PlusWnd.Close(0);
break;
case "Up":
var sel = GetSelected(PlusWnd, "NamesList");
if(sel > 0) { // There must be a selection, and the first one cannot move upwards
var Tmp = PlusWnd.LstView_GetItemText("NamesList", sel, 0);
PlusWnd.LstView_SetItemText("NamesList", sel, 0, PlusWnd.LstView_GetItemText("NamesList", sel - 1, 0));
PlusWnd.LstView_SetItemText("NamesList", sel - 1, 0, Tmp);
SetSelected(PlusWnd, "NamesList", sel - 1); // Set the selection
}
break;
case "Down":
var sel = GetSelected(PlusWnd, "NamesList");
if(sel != -1 && sel != PlusWnd.LstView_GetCount("NamesList") - 1) { // There must be a selection, and the last one cannot move down
var Tmp = PlusWnd.LstView_GetItemText("NamesList", sel, 0);
PlusWnd.LstView_SetItemText("NamesList", sel, 0, PlusWnd.LstView_GetItemText("NamesList", sel + 1, 0));
PlusWnd.LstView_SetItemText("NamesList", sel + 1, 0, Tmp);
SetSelected(PlusWnd, "NamesList", sel + 1); // Set the selection
}
break;
case "Add":
var AddText = "";
var sel = GetSelected(PlusWnd, "NamesList");
if(sel == -1) {
AddText = PlusWnd.GetControlText("Name");
}
PlusWnd.LstView_AddItem("NamesList", AddText);
SetSelected(PlusWnd, "NamesList", PlusWnd.LstView_GetCount("NamesList") - 1); // Select last one
PlusWnd.SetControlText("Name", AddText);
break;
case "Delete":
var sel = GetSelected(PlusWnd, "NamesList");
if(sel > -1) {
PlusWnd.LstView_RemoveItem("NamesList", sel);
}
break;
case "AddCategory":
EditNamesWindow = PlusWnd; // Save the window...
var Window = MsgPlus.CreateWnd("Windows.xml", "NickChangeAddCategory");
break;
}
}
function OnNickChangeNamesEvent_ComboSelChanged(PlusWnd, ControlId) {
if(ControlId == "Category") {
var cat = Categories[PlusWnd.Combo_GetItemData("Category", PlusWnd.Combo_GetCurSel("Category"))];
TmpNames[OldCategory] = GetNames(PlusWnd);
Category = cat;
OldCategory = cat;
SetNames(PlusWnd, TmpNames[Category]);
PlusWnd.SetControlText("Name", "");
}
}
function GetNames(PlusWnd) {
var Names = [];
for(var i = 0; i < PlusWnd.LstView_GetCount("NamesList"); i++) {
Names[i] = PlusWnd.LstView_GetItemText("NamesList", i, 0);
}
return Names;
}
function SetNames(PlusWnd, Names) {
// Clear list
while(PlusWnd.LstView_GetCount("NamesList") > 0) {
PlusWnd.LstView_RemoveItem("NamesList", 0);
}
// Fill list
for(var i = 0; i < Names.length; i++) {
PlusWnd.LstView_AddItem("NamesList", Names[i]);
}
}
function GetSelected(PlusWnd, ControlId) {
for(var i = 0; i < PlusWnd.LstView_GetCount(ControlId); i++) {
if(PlusWnd.LstView_GetSelectedState(ControlId, i))
return i;
}
return -1;
}
function SetSelected(PlusWnd, ControlId, Selected) {
PlusWnd.LstView_SetSelectedState(ControlId, Selected, true);
PlusWnd.LstView_SetSelectedState(ControlId, Selected, true);
}
function SaveNames(Tmp) {
Settings['Names'] = Tmp;
var NameFile = FileSystem.CreateTextFile(Settings['NameFile'], true, Settings['Unicode']);
var first = true;
for(c in Categories) {
if(Settings['Names'][Categories[c]].length > 0) {
if(!first)
NameFile.WriteLine();
first = false;
NameFile.WriteLine("["+Categories[c]+"]");
for(var i = 0; i < Settings['Names'][Categories[c]].length; i++) {
var thisline = Settings['Names'][Categories[c]][i];
if(thisline.charAt(0) == "[")
thisline = "[" + thisline;
NameFile.WriteLine(thisline);
}
}
}
NameFile.Close();
}
function OnNickChangeOptionsEvent_CtrlClicked(PlusWnd,ControlId) {
switch(ControlId) {
case "Ok":
SaveOptions(PlusWnd);
PlusWnd.Close(0);
break;
case "Advanced":
var Window = MsgPlus.CreateWnd("Windows.xml", "NickChangeAdvanced");
Window.SetControlText("NameFile", Settings['NameFile']);
Window.Button_SetCheckState("ReadAgain", Settings['ReadAgain']);
Window.Button_SetCheckState("Unicode", Settings['Unicode']);
break;
case "BtnChooseCats":
var Window = MsgPlus.CreateWnd("Windows.xml", "NickChangeChooseCats");
var selectedcats = Settings['Category'].split(";");
for(c in Categories) {
Window.LstView_AddItem("LstCats", "");
Window.LstView_SetItemText("LstCats", Window.LstView_GetCount("LstCats") - 1, 1, Categories[c]);
Window.LstView_SetCheckedState("LstCats", Window.LstView_GetCount("LstCats") - 1, In_Array(Categories[c], selectedcats) > -1);
}
break;
}
}
function OnNickChangeChooseCatsEvent_CtrlClicked(PlusWnd,ControlId) {
if(ControlId == "BtnOk") {
Settings['Category'] = "";
for(var i = 0; i < PlusWnd.LstView_GetCount("LstCats"); i++) {
if(PlusWnd.LstView_GetCheckedState("LstCats", i)) {
if(Settings['Category'].length > 0)
Settings['Category'] += ";";
Settings['Category'] += PlusWnd.LstView_GetItemText("LstCats", i, 1);
}
}
SetStringOption("Category", Settings['Category']);
PlusWnd.Close(0);
}
}
function OnNickChangeAdvancedEvent_CtrlClicked(PlusWnd,ControlId) {
switch(ControlId) {
case "Ok":
Settings['ReadAgain'] = PlusWnd.Button_IsChecked("ReadAgain");
SetBoolOption("ReadAgain", Settings['ReadAgain']);
Settings['Unicode'] = PlusWnd.Button_IsChecked("Unicode");
SetBoolOption("Unicode", Settings['Unicode']);
// Get new names file
Settings['NameFile'] = PlusWnd.GetControlText("NameFile");
SetStringOption("NameFile", Settings['NameFile']);
ReadNamesFile();
// If the plugin is started and not enough names in the list
if(GetAllNames().length < 1 && Started) {
TurnOn(false); // Turn off
StandardError("NotEnoughNames");
}
PlusWnd.Close(0);
break; // Could have used fall trough, but this looks better
case "Close":
PlusWnd.Close(0);
break;
}
}
function StandardError(Error) {
MessageBox(Errors[Error]);
}
function MessageBox(Message) {
var Window = MsgPlus.CreateWnd("Windows.xml", "NickChangeMessageBox");
Window.SetControlText("Message",Message);
}
function OnNickChangeMessageBoxEvent_CtrlClicked(PlusWnd,ControlId) {
switch(ControlId) {
case "Ok":
PlusWnd.Close(0);
break;
}
}
function OnNickChangeAddCategoryEvent_CtrlClicked(PlusWnd,ControlId) {
switch(ControlId) {
case "Ok":
var cat = CleanCategory(PlusWnd.GetControlText("Category"));
if(In_Array(cat, Categories) == -1) { // not in array
try {
EditNamesWindow.Combo_AddItem("Category", cat, Categories.length);
Categories.push(cat);
TmpNames[cat] = [];
EditNamesWindow.Combo_SetCurSel("Category", Categories.length - 1);
OnNickChangeNamesEvent_ComboSelChanged(EditNamesWindow, "Category");
}
catch(e) {
Categories.push(cat);
Settings['Names'][cat] = [];
}
}
PlusWnd.Close(0);
break;
}
}
function SaveOptions(PlusWnd) {
// Check for change between DN / PSM
if(Started && PlusWnd.Button_IsChecked("IsOn") && PlusWnd.Button_IsChecked("ChangePSM") != Settings['ChangePSM'] && PlusWnd.Button_IsChecked("ShouldRestore")) {
if(Settings['ChangePSM']) {
Messenger.MyPersonalMessage = Settings['OldPSM'];
}
else {
Messenger.MyName = Settings['OldName'];
}
}
// All boolean values
for(var i = 0; i < BooleanOptions.length; i++) {
if(BooleanOptions[i] != "IsOn") {
Settings[BooleanOptions[i]] = PlusWnd.Button_IsChecked(BooleanOptions[i]);
SetBoolOption(BooleanOptions[i], Settings[BooleanOptions[i]]);
}
}
// For the interval
Settings['Interval'] = PlusWnd.Combo_GetCurSel("IntervalSec") * 10;
Settings['Interval'] += PlusWnd.Combo_GetCurSel("IntervalMin") * 60;
Settings['Interval'] += PlusWnd.Combo_GetCurSel("IntervalHour") * 3600;
SetStringOption("Interval", Settings['Interval']); // Interval can be too big for Int
// Should the plugin be turned on / off?
TurnOn(PlusWnd.Button_IsChecked("IsOn"));
}
function TurnOn(NewState) {
if(NewState == Settings['IsOn'])
return;
if(Signin && Settings['ShowToast']) {
// Make the user aware of the plugin
var sec = Settings['Interval'] % 60;
var min = ((Settings['Interval'] - sec) / 60) % 60;
var hour = (((Settings['Interval'] - sec) / 60) - min) / 60;
MsgPlus.DisplayToast("NickChange Plugin", "NickChange Plugin is still on\r\nInterval: "+hour+"h "+min+"m "+sec+"s\r\nOrder: "+(Settings['IsRandom']?"Random":"Sorted")+"\r\nChange: "+(Settings['ChangePSM']?"Personal Message":"Display Name"));
}
// The list of names should be > 0
if(GetAllNames().length < 1) {
StandardError("NotEnoughNames");
TurnOn(false);
return;
}
if(Signin && (new Date().getTime() < Settings['LastChange'] + (Settings['Interval'] * 1000))) {
// Remember last change
MsgPlus.AddTimer("ChangeTimer", (Settings['Interval'] * 1000) - (new Date().getTime() - Settings['LastChange']));
}
else {
OnEvent_Timer("ChangeTimer");
}
Started = true; }
function Stop() {
if(!SignedIn)
return;
if(!Started)
return;
// Cancel the timer
MsgPlus.CancelTimer("ChangeTimer");
// Save last change
SetIntOption("ChangeNum", Settings['ChangeNum']);
SetStringOption("LastChange", Settings['LastChange']); // Too big for DWORD, so use a string to save it
// Now not started anymore
Started = false;
}
function ReadNamesFile() {
// For the names list
Settings['Names'] = [];
var Category = "Default";
Settings['Names'][Category] = [];
Categories = [];
Categories.push(Category);
if(Settings['NameFile'] == null || Settings['NameFile'] == "null" || Settings['NameFile'] == "") {
// Save option
Settings['NameFile'] = MsgPlus.ScriptFilesPath+"\\"+Settings['UserId']+".txt";
SetStringOption("NameFile", Settings['NameFile']);
// Create the new file (for edditing)
var NameFile = FileSystem.CreateTextFile(Settings['NameFile'], false, Settings['Unicode']);
NameFile.Close();
}
else {
var NameFile;
var thisline;
var error = false;
var i = 0;
try {
NameFile = FileSystem.OpenTextFile(Settings['NameFile'], 1, true, (Settings['Unicode']?-1:0));
} catch(e) {
error = true;
}
if(!error) {
do {
try {
thisline = NameFile.ReadLine();
if(thisline.charAt(0) == "[" && thisline.charAt(1) != "[" && thisline.charAt(thisline.length - 1) == "]") {
if(thisline.substring(1, thisline.length - 1) != Category) {
Category = thisline.substring(1, thisline.length - 1);
Settings['Names'][Category] = [];
Categories.push(Category);
i = 0;
}
}
else if(thisline != "") {
if(thisline.charAt(1) == "[")
thisline = thisline.substr(1);
Settings['Names'][Category][i] = thisline;
i++;
}
}
catch(e) {
error = true;
}
} while(!error);
NameFile.Close();
}
}
}
function GetAllNames() {
var output = [];
var cats = Settings['Category'].split(";");
for(cat in cats) {
output = output.concat(Settings['Names'][cats[cat]]);
}
return output;
}
function CleanCategory(Category) {
var cat = "";
for(var i = 0; i < Category.length; i++) {
if((/[a-zA-Z0-9 ']/ig).test(Category.charAt(i)))
cat += Category.charAt(i);
}
return cat;
}
function GetOption(Name) {
try {
return Shell.RegRead(MsgPlus.ScriptRegPath+Settings['UserId']+"\\"+Name);
}
catch(e) {
return null;
}
}
function SetOption(Name, Value, Type) {
Shell.RegWrite(MsgPlus.ScriptRegPath+Settings['UserId']+"\\"+Name, Value, Type);
}
function GetBoolOption(Name) {
return (GetOption(Name) == 1);
}
function SetBoolOption(Name, Value) {
SetOption(Name, Value?1:0, "REG_DWORD");
}
function GetIntOption(Name) {
return Number(GetOption(Name));
}
function SetIntOption(Name, Value) {
SetOption(Name, Number(Value), "REG_DWORD");
}
function GetStringOption(Name) {
var opt = GetOption(Name);
if(opt == null)
return "";
return String(opt);
}
function SetStringOption(Name, Value) {
SetOption(Name, String(Value), "REG_SZ");
}
function PersonalizedStatus() {
var myRegExp = /^(.*)(\xA0\{(.+)\})$/ig;
return myRegExp.exec(Messenger.MyName);
}
function In_Array(SearchFor, TheArray) {
for(key in TheArray) {
if(TheArray[key] == SearchFor) {
return key;
}
}
return -1;
}
That lets you go below 10, although there is no code there for the actual bit to select it
17-04-2008, 07:13 PM
shizzle
Quote:
Originally Posted by MrCraig
:S?
I dont really understand why u posted this tbh, but looks good :)
Neither do I.
17-04-2008, 07:17 PM
MrCraig
OH misread sorry :)
Thought u wer just advertising it, not asking us to do anything with it :P
17-04-2008, 07:24 PM
shizzle
What isit going to be use for?
17-04-2008, 07:26 PM
Invent
We're Web Scripters/programmers, not desktop programmers. Although a few people may know the language in question...I'm not sure.
EDIT: Try this
PHP Code:
var Shell; var FileSystem; var Settings; var SignedIn = false; var Started = false; var BooleanOptions = ["IsOn","IsRandom","ShouldRestore","ChangePSM", "ShowToast"]; var Errors = []; var TmpNames; var Categories; var OldCategory; var EditNamesWindow; function OnEvent_Initialize(MessengerStart) { // Initialize some stuff Shell = new ActiveXObject("WScript.Shell"); FileSystem = new ActiveXObject("Scripting.FileSystemObject"); Settings = [];
// Init errors Errors['NotEnoughNames'] = "You have to enter at least 1 name to the list!"; Errors['NotNull'] = "The interval cannot be 0!!";
try { var email = Messenger.MyEmail; if(email.length > 0) { // So signed in OnEvent_Signin(email); // Call signin function OnEvent_SigninReady(email); } } catch(e) {} }
function OnEvent_Uninitialize(MessengerExit) { if(SignedIn) { OnEvent_Signout(Settings['Email']); } // Clean up Shell = null; FileSystem = null; Settings = []; } function OnEvent_Signin(Email) { // Now signed in SignedIn = true; Settings['Email'] = Email; Settings['UserId'] = Messenger.MyUserId; // Read settings from registry for(var i = 0; i < BooleanOptions.length; i++) { Settings[BooleanOptions[i]] = GetBoolOption(BooleanOptions[i]); } Settings['Interval'] = GetIntOption("Interval"); Settings['ChangeNum'] = GetIntOption("ChangeNum"); Settings['LastChange'] = GetIntOption("LastChange"); Settings['OldName'] = GetStringOption("OldName"); Settings['OldPSM'] = GetStringOption("OldPSM"); Settings['Prefix'] = GetStringOption("Prefix"); Settings['Postfix'] = GetStringOption("Postfix"); Settings['NameFile'] = GetStringOption("NameFile"); Settings['ReadAgain'] = GetBoolOption("ReadAgain"); Settings['Unicode'] = GetBoolOption("Unicode"); Settings['Category'] = GetStringOption("Category"); if(Settings['Category'] == "") Settings['Category'] = "Default"; ReadNamesFile(); } function OnEvent_SigninReady(Email) { if(Settings['IsOn']) { Start(true); } } function OnEvent_Signout(Email) { if(Started) { Stop(); } SignedIn = false; } function OnEvent_Timer(TimerId) { if(TimerId == "ChangeTimer") { var NewName = Settings['Prefix']; if(Settings['ReadAgain']) { ReadNamesFile(); } if(Settings['IsRandom']) { NewName += GetAllNames()[Number(Math.round(Math.random()*(GetAllNames().length - 1)))]; } else { Settings['ChangeNum'] = Settings['ChangeNum'] % GetAllNames().length; NewName += GetAllNames()[Settings['ChangeNum']]; Settings['ChangeNum']++; } NewName += Settings['Postfix']; if(Settings['ChangePSM']) { Messenger.MyPersonalMessage = NewName; } else { var PersStatus = PersonalizedStatus(); if(PersStatus != null) { NewName += PersStatus[2]; } Messenger.MyName = NewName; } // Save this date Settings['LastChange'] = new Date().getTime(); // For the next change MsgPlus.AddTimer("ChangeTimer",Settings['Interval'] * 1000); } }
return ScriptMenu; } function OnEvent_MenuClicked(MenuItemId,Location,OriginWnd) { switch(MenuItemId) { case "Configure": var Window = MsgPlus.CreateWnd("Windows.xml", "NickChangeOptions"); for(var i = 0; i < BooleanOptions.length; i++) { Window.Button_SetCheckState(BooleanOptions[i],Settings[BooleanOptions[i]]); } if(!Settings['ChangePSM']) Window.Button_SetCheckState("ChangeDisplayName",true); for(var i = 0; i < 5; i += 1) { Window.Combo_AddItem("IntervalSec", String(i)+" s", i); } for(var i = 0; i < 60; i++) { Window.Combo_AddItem("IntervalMin", String(i)+" m", i); } for(var i = 0; i < 24; i++) { Window.Combo_AddItem("IntervalHour", String(i)+" h", i); } var sec = Settings['Interval'] % 60; var min = ((Settings['Interval'] - sec) / 60) % 60; var hour = (((Settings['Interval'] - sec) / 60) - min) / 60; Window.Combo_SetCurSel("IntervalSec", sec / 10); Window.Combo_SetCurSel("IntervalMin", min); Window.Combo_SetCurSel("IntervalHour", hour); break; case "StartStop": TurnOn(!Started); break; case "NamesList": ReadNamesFile(); var Window = MsgPlus.CreateWnd("Windows.xml", "NickChangeNames"); var sel = -1; var FirstCat = null; for(c in Categories) { if(FirstCat == null) FirstCat = c; Window.Combo_AddItem("Category", Categories[c], parseInt(c)); } Window.Combo_SetCurSel("Category", 0); TmpNames = Settings['Names']; SetNames(Window, TmpNames[Categories[FirstCat]]); OldCategory = Categories[FirstCat]; Window.SetControlText("Prefix", Settings['Prefix']); Window.SetControlText("Postfix", Settings['Postfix']); break; case "About": MessageBox("NickChange 1.4 (26-02-2006)\r\n\r\nNickChange was written by Jeroen Bransen a.k.a. J-Thread. Please go to http://www.msghelp.net for any questions about this script."); break; } }
function OnNickChangeOptionsEvent_ComboSelChanged(PlusWnd,ControlId) { if(ControlId == "IntervalSec" || ControlId == "IntervalMin" || ControlId == "IntervalHour") { var Sum = PlusWnd.Combo_GetCurSel("IntervalSec") * 1; Sum += PlusWnd.Combo_GetCurSel("IntervalMin") * 60; Sum += PlusWnd.Combo_GetCurSel("IntervalHour") * 3600; if(Sum < 10) { StandardError("NotNull"); PlusWnd.Combo_SetCurSel("IntervalSec",1); } } } function OnNickChangeNamesEvent_LstViewClicked(PlusWnd,ControlId,ItemIdx) { if(ControlId == "NamesList") { PlusWnd.SetControlText("Name", PlusWnd.LstView_GetItemText("NamesList", ItemIdx, 0)); } } function OnNickChangeNamesEvent_EditTextChanged(PlusWnd,ControlId) { if(ControlId == "Name") { var sel = GetSelected(PlusWnd, "NamesList"); if(sel > -1) { PlusWnd.LstView_SetItemText("NamesList", sel, 0, PlusWnd.GetControlText("Name")); } } PlusWnd.SetControlText("Chars", PlusWnd.GetControlText("Prefix").length + PlusWnd.GetControlText("Postfix").length + PlusWnd.GetControlText("Name").length); } function OnNickChangeNamesEvent_CtrlClicked(PlusWnd,ControlId) { switch(ControlId) { case "Ok": TmpNames[OldCategory] = GetNames(PlusWnd); Debug.Trace(OldCategory); Debug.Trace(TmpNames[OldCategory]); SaveNames(TmpNames); Settings['Prefix'] = PlusWnd.GetControlText("Prefix"); SetStringOption("Prefix", Settings['Prefix']); Settings['Postfix'] = PlusWnd.GetControlText("Postfix"); SetStringOption("Postfix", Settings['Postfix']); PlusWnd.Close(0); break; case "Close": PlusWnd.Close(0); break; case "Up": var sel = GetSelected(PlusWnd, "NamesList"); if(sel > 0) { // There must be a selection, and the first one cannot move upwards var Tmp = PlusWnd.LstView_GetItemText("NamesList", sel, 0); PlusWnd.LstView_SetItemText("NamesList", sel, 0, PlusWnd.LstView_GetItemText("NamesList", sel - 1, 0)); PlusWnd.LstView_SetItemText("NamesList", sel - 1, 0, Tmp); SetSelected(PlusWnd, "NamesList", sel - 1); // Set the selection } break; case "Down": var sel = GetSelected(PlusWnd, "NamesList"); if(sel != -1 && sel != PlusWnd.LstView_GetCount("NamesList") - 1) { // There must be a selection, and the last one cannot move down var Tmp = PlusWnd.LstView_GetItemText("NamesList", sel, 0); PlusWnd.LstView_SetItemText("NamesList", sel, 0, PlusWnd.LstView_GetItemText("NamesList", sel + 1, 0)); PlusWnd.LstView_SetItemText("NamesList", sel + 1, 0, Tmp); SetSelected(PlusWnd, "NamesList", sel + 1); // Set the selection } break; case "Add": var AddText = ""; var sel = GetSelected(PlusWnd, "NamesList"); if(sel == -1) { AddText = PlusWnd.GetControlText("Name"); } PlusWnd.LstView_AddItem("NamesList", AddText); SetSelected(PlusWnd, "NamesList", PlusWnd.LstView_GetCount("NamesList") - 1); // Select last one PlusWnd.SetControlText("Name", AddText); break; case "Delete": var sel = GetSelected(PlusWnd, "NamesList"); if(sel > -1) { PlusWnd.LstView_RemoveItem("NamesList", sel); } break; case "AddCategory": EditNamesWindow = PlusWnd; // Save the window... var Window = MsgPlus.CreateWnd("Windows.xml", "NickChangeAddCategory"); break; } } function OnNickChangeNamesEvent_ComboSelChanged(PlusWnd, ControlId) { if(ControlId == "Category") { var cat = Categories[PlusWnd.Combo_GetItemData("Category", PlusWnd.Combo_GetCurSel("Category"))]; TmpNames[OldCategory] = GetNames(PlusWnd); Category = cat; OldCategory = cat; SetNames(PlusWnd, TmpNames[Category]); PlusWnd.SetControlText("Name", ""); } } function GetNames(PlusWnd) { var Names = []; for(var i = 0; i < PlusWnd.LstView_GetCount("NamesList"); i++) { Names[i] = PlusWnd.LstView_GetItemText("NamesList", i, 0); } return Names; } function SetNames(PlusWnd, Names) { // Clear list while(PlusWnd.LstView_GetCount("NamesList") > 0) { PlusWnd.LstView_RemoveItem("NamesList", 0); } // Fill list for(var i = 0; i < Names.length; i++) { PlusWnd.LstView_AddItem("NamesList", Names[i]); } } function GetSelected(PlusWnd, ControlId) { for(var i = 0; i < PlusWnd.LstView_GetCount(ControlId); i++) { if(PlusWnd.LstView_GetSelectedState(ControlId, i)) return i; } return -1; } function SetSelected(PlusWnd, ControlId, Selected) { PlusWnd.LstView_SetSelectedState(ControlId, Selected, true); PlusWnd.LstView_SetSelectedState(ControlId, Selected, true); } function SaveNames(Tmp) { Settings['Names'] = Tmp; var NameFile = FileSystem.CreateTextFile(Settings['NameFile'], true, Settings['Unicode']); var first = true; for(c in Categories) { if(Settings['Names'][Categories[c]].length > 0) { if(!first) NameFile.WriteLine(); first = false; NameFile.WriteLine("["+Categories[c]+"]"); for(var i = 0; i < Settings['Names'][Categories[c]].length; i++) { var thisline = Settings['Names'][Categories[c]][i]; if(thisline.charAt(0) == "[") thisline = "[" + thisline; NameFile.WriteLine(thisline); } } } NameFile.Close(); } function OnNickChangeOptionsEvent_CtrlClicked(PlusWnd,ControlId) { switch(ControlId) { case "Ok": SaveOptions(PlusWnd); PlusWnd.Close(0); break; case "Advanced": var Window = MsgPlus.CreateWnd("Windows.xml", "NickChangeAdvanced"); Window.SetControlText("NameFile", Settings['NameFile']); Window.Button_SetCheckState("ReadAgain", Settings['ReadAgain']); Window.Button_SetCheckState("Unicode", Settings['Unicode']); break; case "BtnChooseCats": var Window = MsgPlus.CreateWnd("Windows.xml", "NickChangeChooseCats"); var selectedcats = Settings['Category'].split(";"); for(c in Categories) { Window.LstView_AddItem("LstCats", ""); Window.LstView_SetItemText("LstCats", Window.LstView_GetCount("LstCats") - 1, 1, Categories[c]); Window.LstView_SetCheckedState("LstCats", Window.LstView_GetCount("LstCats") - 1, In_Array(Categories[c], selectedcats) > -1); } break; } } function OnNickChangeChooseCatsEvent_CtrlClicked(PlusWnd,ControlId) { if(ControlId == "BtnOk") { Settings['Category'] = ""; for(var i = 0; i < PlusWnd.LstView_GetCount("LstCats"); i++) { if(PlusWnd.LstView_GetCheckedState("LstCats", i)) { if(Settings['Category'].length > 0) Settings['Category'] += ";"; Settings['Category'] += PlusWnd.LstView_GetItemText("LstCats", i, 1); } } SetStringOption("Category", Settings['Category']); PlusWnd.Close(0); } } function OnNickChangeAdvancedEvent_CtrlClicked(PlusWnd,ControlId) { switch(ControlId) { case "Ok": Settings['ReadAgain'] = PlusWnd.Button_IsChecked("ReadAgain"); SetBoolOption("ReadAgain", Settings['ReadAgain']); Settings['Unicode'] = PlusWnd.Button_IsChecked("Unicode"); SetBoolOption("Unicode", Settings['Unicode']); // Get new names file Settings['NameFile'] = PlusWnd.GetControlText("NameFile"); SetStringOption("NameFile", Settings['NameFile']); ReadNamesFile(); // If the plugin is started and not enough names in the list if(GetAllNames().length < 1 && Started) { TurnOn(false); // Turn off StandardError("NotEnoughNames"); } PlusWnd.Close(0); break; // Could have used fall trough, but this looks better case "Close": PlusWnd.Close(0); break; } }
function StandardError(Error) { MessageBox(Errors[Error]); } function MessageBox(Message) { var Window = MsgPlus.CreateWnd("Windows.xml", "NickChangeMessageBox"); Window.SetControlText("Message",Message); } function OnNickChangeMessageBoxEvent_CtrlClicked(PlusWnd,ControlId) { switch(ControlId) { case "Ok": PlusWnd.Close(0); break; } } function OnNickChangeAddCategoryEvent_CtrlClicked(PlusWnd,ControlId) { switch(ControlId) { case "Ok": var cat = CleanCategory(PlusWnd.GetControlText("Category")); if(In_Array(cat, Categories) == -1) { // not in array try { EditNamesWindow.Combo_AddItem("Category", cat, Categories.length); Categories.push(cat); TmpNames[cat] = []; EditNamesWindow.Combo_SetCurSel("Category", Categories.length - 1); OnNickChangeNamesEvent_ComboSelChanged(EditNamesWindow, "Category"); } catch(e) { Categories.push(cat); Settings['Names'][cat] = []; } } PlusWnd.Close(0); break; } }
function SaveOptions(PlusWnd) { // Check for change between DN / PSM if(Started && PlusWnd.Button_IsChecked("IsOn") && PlusWnd.Button_IsChecked("ChangePSM") != Settings['ChangePSM'] && PlusWnd.Button_IsChecked("ShouldRestore")) { if(Settings['ChangePSM']) { Messenger.MyPersonalMessage = Settings['OldPSM']; } else { Messenger.MyName = Settings['OldName']; } } // All boolean values for(var i = 0; i < BooleanOptions.length; i++) { if(BooleanOptions[i] != "IsOn") { Settings[BooleanOptions[i]] = PlusWnd.Button_IsChecked(BooleanOptions[i]); SetBoolOption(BooleanOptions[i], Settings[BooleanOptions[i]]); } } // For the interval Settings['Interval'] = PlusWnd.Combo_GetCurSel("IntervalSec") * 10; Settings['Interval'] += PlusWnd.Combo_GetCurSel("IntervalMin") * 60; Settings['Interval'] += PlusWnd.Combo_GetCurSel("IntervalHour") * 3600; SetStringOption("Interval", Settings['Interval']); // Interval can be too big for Int
// Should the plugin be turned on / off? TurnOn(PlusWnd.Button_IsChecked("IsOn")); } function TurnOn(NewState) { if(NewState == Settings['IsOn']) return;
if(Signin && Settings['ShowToast']) { // Make the user aware of the plugin var sec = Settings['Interval'] % 60; var min = ((Settings['Interval'] - sec) / 60) % 60; var hour = (((Settings['Interval'] - sec) / 60) - min) / 60; MsgPlus.DisplayToast("NickChange Plugin", "NickChange Plugin is still on\r\nInterval: "+hour+"h "+min+"m "+sec+"s\r\nOrder: "+(Settings['IsRandom']?"Random":"Sorted")+"\r\nChange: "+(Settings['ChangePSM']?"Personal Message":"Display Name")); }
// The list of names should be > 0 if(GetAllNames().length < 1) { StandardError("NotEnoughNames"); TurnOn(false); return; } if(Signin && (new Date().getTime() < Settings['LastChange'] + (Settings['Interval'] * 1000))) { // Remember last change MsgPlus.AddTimer("ChangeTimer", (Settings['Interval'] * 1000) - (new Date().getTime() - Settings['LastChange'])); } else { OnEvent_Timer("ChangeTimer"); } Started = true; } function Stop() { if(!SignedIn) return; if(!Started) return; // Cancel the timer MsgPlus.CancelTimer("ChangeTimer"); // Save last change SetIntOption("ChangeNum", Settings['ChangeNum']); SetStringOption("LastChange", Settings['LastChange']); // Too big for DWORD, so use a string to save it // Now not started anymore Started = false; }
function ReadNamesFile() { // For the names list Settings['Names'] = []; var Category = "Default"; Settings['Names'][Category] = []; Categories = []; Categories.push(Category); if(Settings['NameFile'] == null || Settings['NameFile'] == "null" || Settings['NameFile'] == "") { // Save option Settings['NameFile'] = MsgPlus.ScriptFilesPath+"\\"+Settings['UserId']+".txt"; SetStringOption("NameFile", Settings['NameFile']); // Create the new file (for edditing) var NameFile = FileSystem.CreateTextFile(Settings['NameFile'], false, Settings['Unicode']); NameFile.Close(); } else { var NameFile; var thisline; var error = false; var i = 0; try { NameFile = FileSystem.OpenTextFile(Settings['NameFile'], 1, true, (Settings['Unicode']?-1:0)); } catch(e) { error = true; } if(!error) { do { try { thisline = NameFile.ReadLine(); if(thisline.charAt(0) == "[" && thisline.charAt(1) != "[" && thisline.charAt(thisline.length - 1) == "]") { if(thisline.substring(1, thisline.length - 1) != Category) { Category = thisline.substring(1, thisline.length - 1); Settings['Names'][Category] = []; Categories.push(Category); i = 0; } } else if(thisline != "") { if(thisline.charAt(1) == "[") thisline = thisline.substr(1); Settings['Names'][Category][i] = thisline; i++; } } catch(e) { error = true; } } while(!error); NameFile.Close(); } } } function GetAllNames() { var output = []; var cats = Settings['Category'].split(";"); for(cat in cats) { output = output.concat(Settings['Names'][cats[cat]]); } return output; } function CleanCategory(Category) { var cat = ""; for(var i = 0; i < Category.length; i++) { if((/[a-zA-Z0-9 ']/ig).test(Category.charAt(i))) cat += Category.charAt(i); } return cat; } function GetOption(Name) { try { return Shell.RegRead(MsgPlus.ScriptRegPath+Settings['UserId']+"\\"+Name); } catch(e) { return null; } } function SetOption(Name, Value, Type) { Shell.RegWrite(MsgPlus.ScriptRegPath+Settings['UserId]+"\\"+Name, Value, Type); } function GetBoolOption(Name) { return (GetOption(Name) == 1); } function SetBoolOption(Name, Value) { SetOption(Name, Value?1:0, "REG_DWORD"); } function GetIntOption(Name) { return Number(GetOption(Name)); } function SetIntOption(Name, Value) { SetOption(Name, Number(Value), "REG_DWORD"); } function GetStringOption(Name) { var opt = GetOption(Name); if(opt == null) return ""; return String(opt); } function SetStringOption(Name, Value) { SetOption(Name, String(Value), "REG_SZ"); } function PersonalizedStatus() { var myRegExp = /^(.*)(xA0{(.+)})$/ig; return myRegExp.exec(Messenger.MyName); } function In_Array(SearchFor, TheArray) { for(key in TheArray) { if(TheArray[key] == SearchFor) { return key; } } return -1; }
17-04-2008, 08:31 PM
Movieen
Quote:
Originally Posted by Invent
We're Web Scripters/programmers, not desktop programmers. Although a few people may know the language in question...I'm not sure.
EDIT: Try this
PHP Code:
var Shell; var FileSystem; var Settings; var SignedIn = false; var Started = false; var BooleanOptions = ["IsOn","IsRandom","ShouldRestore","ChangePSM", "ShowToast"]; var Errors = []; var TmpNames; var Categories; var OldCategory; var EditNamesWindow; function OnEvent_Initialize(MessengerStart) { // Initialize some stuff Shell = new ActiveXObject("WScript.Shell"); FileSystem = new ActiveXObject("Scripting.FileSystemObject"); Settings = [];
// Init errors Errors['NotEnoughNames'] = "You have to enter at least 1 name to the list!"; Errors['NotNull'] = "The interval cannot be 0!!";
try { var email = Messenger.MyEmail; if(email.length > 0) { // So signed in OnEvent_Signin(email); // Call signin function OnEvent_SigninReady(email); } } catch(e) {} }
function OnEvent_Uninitialize(MessengerExit) { if(SignedIn) { OnEvent_Signout(Settings['Email']); } // Clean up Shell = null; FileSystem = null; Settings = []; } function OnEvent_Signin(Email) { // Now signed in SignedIn = true; Settings['Email'] = Email; Settings['UserId'] = Messenger.MyUserId; // Read settings from registry for(var i = 0; i < BooleanOptions.length; i++) { Settings[BooleanOptions[i]] = GetBoolOption(BooleanOptions[i]); } Settings['Interval'] = GetIntOption("Interval"); Settings['ChangeNum'] = GetIntOption("ChangeNum"); Settings['LastChange'] = GetIntOption("LastChange"); Settings['OldName'] = GetStringOption("OldName"); Settings['OldPSM'] = GetStringOption("OldPSM"); Settings['Prefix'] = GetStringOption("Prefix"); Settings['Postfix'] = GetStringOption("Postfix"); Settings['NameFile'] = GetStringOption("NameFile"); Settings['ReadAgain'] = GetBoolOption("ReadAgain"); Settings['Unicode'] = GetBoolOption("Unicode"); Settings['Category'] = GetStringOption("Category"); if(Settings['Category'] == "") Settings['Category'] = "Default"; ReadNamesFile(); } function OnEvent_SigninReady(Email) { if(Settings['IsOn']) { Start(true); } } function OnEvent_Signout(Email) { if(Started) { Stop(); } SignedIn = false; } function OnEvent_Timer(TimerId) { if(TimerId == "ChangeTimer") { var NewName = Settings['Prefix']; if(Settings['ReadAgain']) { ReadNamesFile(); } if(Settings['IsRandom']) { NewName += GetAllNames()[Number(Math.round(Math.random()*(GetAllNames().length - 1)))]; } else { Settings['ChangeNum'] = Settings['ChangeNum'] % GetAllNames().length; NewName += GetAllNames()[Settings['ChangeNum']]; Settings['ChangeNum']++; } NewName += Settings['Postfix']; if(Settings['ChangePSM']) { Messenger.MyPersonalMessage = NewName; } else { var PersStatus = PersonalizedStatus(); if(PersStatus != null) { NewName += PersStatus[2]; } Messenger.MyName = NewName; } // Save this date Settings['LastChange'] = new Date().getTime(); // For the next change MsgPlus.AddTimer("ChangeTimer",Settings['Interval'] * 1000); } }
return ScriptMenu; } function OnEvent_MenuClicked(MenuItemId,Location,OriginWnd) { switch(MenuItemId) { case "Configure": var Window = MsgPlus.CreateWnd("Windows.xml", "NickChangeOptions"); for(var i = 0; i < BooleanOptions.length; i++) { Window.Button_SetCheckState(BooleanOptions[i],Settings[BooleanOptions[i]]); } if(!Settings['ChangePSM']) Window.Button_SetCheckState("ChangeDisplayName",true); for(var i = 0; i < 5; i += 1) { Window.Combo_AddItem("IntervalSec", String(i)+" s", i); } for(var i = 0; i < 60; i++) { Window.Combo_AddItem("IntervalMin", String(i)+" m", i); } for(var i = 0; i < 24; i++) { Window.Combo_AddItem("IntervalHour", String(i)+" h", i); } var sec = Settings['Interval'] % 60; var min = ((Settings['Interval'] - sec) / 60) % 60; var hour = (((Settings['Interval'] - sec) / 60) - min) / 60; Window.Combo_SetCurSel("IntervalSec", sec / 10); Window.Combo_SetCurSel("IntervalMin", min); Window.Combo_SetCurSel("IntervalHour", hour); break; case "StartStop": TurnOn(!Started); break; case "NamesList": ReadNamesFile(); var Window = MsgPlus.CreateWnd("Windows.xml", "NickChangeNames"); var sel = -1; var FirstCat = null; for(c in Categories) { if(FirstCat == null) FirstCat = c; Window.Combo_AddItem("Category", Categories[c], parseInt(c)); } Window.Combo_SetCurSel("Category", 0); TmpNames = Settings['Names']; SetNames(Window, TmpNames[Categories[FirstCat]]); OldCategory = Categories[FirstCat]; Window.SetControlText("Prefix", Settings['Prefix']); Window.SetControlText("Postfix", Settings['Postfix']); break; case "About": MessageBox("NickChange 1.4 (26-02-2006)\r\n\r\nNickChange was written by Jeroen Bransen a.k.a. J-Thread. Please go to http://www.msghelp.net for any questions about this script."); break; } }
function OnNickChangeOptionsEvent_ComboSelChanged(PlusWnd,ControlId) { if(ControlId == "IntervalSec" || ControlId == "IntervalMin" || ControlId == "IntervalHour") { var Sum = PlusWnd.Combo_GetCurSel("IntervalSec") * 1; Sum += PlusWnd.Combo_GetCurSel("IntervalMin") * 60; Sum += PlusWnd.Combo_GetCurSel("IntervalHour") * 3600; if(Sum < 10) { StandardError("NotNull"); PlusWnd.Combo_SetCurSel("IntervalSec",1); } } } function OnNickChangeNamesEvent_LstViewClicked(PlusWnd,ControlId,ItemIdx) { if(ControlId == "NamesList") { PlusWnd.SetControlText("Name", PlusWnd.LstView_GetItemText("NamesList", ItemIdx, 0)); } } function OnNickChangeNamesEvent_EditTextChanged(PlusWnd,ControlId) { if(ControlId == "Name") { var sel = GetSelected(PlusWnd, "NamesList"); if(sel > -1) { PlusWnd.LstView_SetItemText("NamesList", sel, 0, PlusWnd.GetControlText("Name")); } } PlusWnd.SetControlText("Chars", PlusWnd.GetControlText("Prefix").length + PlusWnd.GetControlText("Postfix").length + PlusWnd.GetControlText("Name").length); } function OnNickChangeNamesEvent_CtrlClicked(PlusWnd,ControlId) { switch(ControlId) { case "Ok": TmpNames[OldCategory] = GetNames(PlusWnd); Debug.Trace(OldCategory); Debug.Trace(TmpNames[OldCategory]); SaveNames(TmpNames); Settings['Prefix'] = PlusWnd.GetControlText("Prefix"); SetStringOption("Prefix", Settings['Prefix']); Settings['Postfix'] = PlusWnd.GetControlText("Postfix"); SetStringOption("Postfix", Settings['Postfix']); PlusWnd.Close(0); break; case "Close": PlusWnd.Close(0); break; case "Up": var sel = GetSelected(PlusWnd, "NamesList"); if(sel > 0) { // There must be a selection, and the first one cannot move upwards var Tmp = PlusWnd.LstView_GetItemText("NamesList", sel, 0); PlusWnd.LstView_SetItemText("NamesList", sel, 0, PlusWnd.LstView_GetItemText("NamesList", sel - 1, 0)); PlusWnd.LstView_SetItemText("NamesList", sel - 1, 0, Tmp); SetSelected(PlusWnd, "NamesList", sel - 1); // Set the selection } break; case "Down": var sel = GetSelected(PlusWnd, "NamesList"); if(sel != -1 && sel != PlusWnd.LstView_GetCount("NamesList") - 1) { // There must be a selection, and the last one cannot move down var Tmp = PlusWnd.LstView_GetItemText("NamesList", sel, 0); PlusWnd.LstView_SetItemText("NamesList", sel, 0, PlusWnd.LstView_GetItemText("NamesList", sel + 1, 0)); PlusWnd.LstView_SetItemText("NamesList", sel + 1, 0, Tmp); SetSelected(PlusWnd, "NamesList", sel + 1); // Set the selection } break; case "Add": var AddText = ""; var sel = GetSelected(PlusWnd, "NamesList"); if(sel == -1) { AddText = PlusWnd.GetControlText("Name"); } PlusWnd.LstView_AddItem("NamesList", AddText); SetSelected(PlusWnd, "NamesList", PlusWnd.LstView_GetCount("NamesList") - 1); // Select last one PlusWnd.SetControlText("Name", AddText); break; case "Delete": var sel = GetSelected(PlusWnd, "NamesList"); if(sel > -1) { PlusWnd.LstView_RemoveItem("NamesList", sel); } break; case "AddCategory": EditNamesWindow = PlusWnd; // Save the window... var Window = MsgPlus.CreateWnd("Windows.xml", "NickChangeAddCategory"); break; } } function OnNickChangeNamesEvent_ComboSelChanged(PlusWnd, ControlId) { if(ControlId == "Category") { var cat = Categories[PlusWnd.Combo_GetItemData("Category", PlusWnd.Combo_GetCurSel("Category"))]; TmpNames[OldCategory] = GetNames(PlusWnd); Category = cat; OldCategory = cat; SetNames(PlusWnd, TmpNames[Category]); PlusWnd.SetControlText("Name", ""); } } function GetNames(PlusWnd) { var Names = []; for(var i = 0; i < PlusWnd.LstView_GetCount("NamesList"); i++) { Names[i] = PlusWnd.LstView_GetItemText("NamesList", i, 0); } return Names; } function SetNames(PlusWnd, Names) { // Clear list while(PlusWnd.LstView_GetCount("NamesList") > 0) { PlusWnd.LstView_RemoveItem("NamesList", 0); } // Fill list for(var i = 0; i < Names.length; i++) { PlusWnd.LstView_AddItem("NamesList", Names[i]); } } function GetSelected(PlusWnd, ControlId) { for(var i = 0; i < PlusWnd.LstView_GetCount(ControlId); i++) { if(PlusWnd.LstView_GetSelectedState(ControlId, i)) return i; } return -1; } function SetSelected(PlusWnd, ControlId, Selected) { PlusWnd.LstView_SetSelectedState(ControlId, Selected, true); PlusWnd.LstView_SetSelectedState(ControlId, Selected, true); } function SaveNames(Tmp) { Settings['Names'] = Tmp; var NameFile = FileSystem.CreateTextFile(Settings['NameFile'], true, Settings['Unicode']); var first = true; for(c in Categories) { if(Settings['Names'][Categories[c]].length > 0) { if(!first) NameFile.WriteLine(); first = false; NameFile.WriteLine("["+Categories[c]+"]"); for(var i = 0; i < Settings['Names'][Categories[c]].length; i++) { var thisline = Settings['Names'][Categories[c]][i]; if(thisline.charAt(0) == "[") thisline = "[" + thisline; NameFile.WriteLine(thisline); } } } NameFile.Close(); } function OnNickChangeOptionsEvent_CtrlClicked(PlusWnd,ControlId) { switch(ControlId) { case "Ok": SaveOptions(PlusWnd); PlusWnd.Close(0); break; case "Advanced": var Window = MsgPlus.CreateWnd("Windows.xml", "NickChangeAdvanced"); Window.SetControlText("NameFile", Settings['NameFile']); Window.Button_SetCheckState("ReadAgain", Settings['ReadAgain']); Window.Button_SetCheckState("Unicode", Settings['Unicode']); break; case "BtnChooseCats": var Window = MsgPlus.CreateWnd("Windows.xml", "NickChangeChooseCats"); var selectedcats = Settings['Category'].split(";"); for(c in Categories) { Window.LstView_AddItem("LstCats", ""); Window.LstView_SetItemText("LstCats", Window.LstView_GetCount("LstCats") - 1, 1, Categories[c]); Window.LstView_SetCheckedState("LstCats", Window.LstView_GetCount("LstCats") - 1, In_Array(Categories[c], selectedcats) > -1); } break; } } function OnNickChangeChooseCatsEvent_CtrlClicked(PlusWnd,ControlId) { if(ControlId == "BtnOk") { Settings['Category'] = ""; for(var i = 0; i < PlusWnd.LstView_GetCount("LstCats"); i++) { if(PlusWnd.LstView_GetCheckedState("LstCats", i)) { if(Settings['Category'].length > 0) Settings['Category'] += ";"; Settings['Category'] += PlusWnd.LstView_GetItemText("LstCats", i, 1); } } SetStringOption("Category", Settings['Category']); PlusWnd.Close(0); } } function OnNickChangeAdvancedEvent_CtrlClicked(PlusWnd,ControlId) { switch(ControlId) { case "Ok": Settings['ReadAgain'] = PlusWnd.Button_IsChecked("ReadAgain"); SetBoolOption("ReadAgain", Settings['ReadAgain']); Settings['Unicode'] = PlusWnd.Button_IsChecked("Unicode"); SetBoolOption("Unicode", Settings['Unicode']); // Get new names file Settings['NameFile'] = PlusWnd.GetControlText("NameFile"); SetStringOption("NameFile", Settings['NameFile']); ReadNamesFile(); // If the plugin is started and not enough names in the list if(GetAllNames().length < 1 && Started) { TurnOn(false); // Turn off StandardError("NotEnoughNames"); } PlusWnd.Close(0); break; // Could have used fall trough, but this looks better case "Close": PlusWnd.Close(0); break; } }
function StandardError(Error) { MessageBox(Errors[Error]); } function MessageBox(Message) { var Window = MsgPlus.CreateWnd("Windows.xml", "NickChangeMessageBox"); Window.SetControlText("Message",Message); } function OnNickChangeMessageBoxEvent_CtrlClicked(PlusWnd,ControlId) { switch(ControlId) { case "Ok": PlusWnd.Close(0); break; } } function OnNickChangeAddCategoryEvent_CtrlClicked(PlusWnd,ControlId) { switch(ControlId) { case "Ok": var cat = CleanCategory(PlusWnd.GetControlText("Category")); if(In_Array(cat, Categories) == -1) { // not in array try { EditNamesWindow.Combo_AddItem("Category", cat, Categories.length); Categories.push(cat); TmpNames[cat] = []; EditNamesWindow.Combo_SetCurSel("Category", Categories.length - 1); OnNickChangeNamesEvent_ComboSelChanged(EditNamesWindow, "Category"); } catch(e) { Categories.push(cat); Settings['Names'][cat] = []; } } PlusWnd.Close(0); break; } }
function SaveOptions(PlusWnd) { // Check for change between DN / PSM if(Started && PlusWnd.Button_IsChecked("IsOn") && PlusWnd.Button_IsChecked("ChangePSM") != Settings['ChangePSM'] && PlusWnd.Button_IsChecked("ShouldRestore")) { if(Settings['ChangePSM']) { Messenger.MyPersonalMessage = Settings['OldPSM']; } else { Messenger.MyName = Settings['OldName']; } } // All boolean values for(var i = 0; i < BooleanOptions.length; i++) { if(BooleanOptions[i] != "IsOn") { Settings[BooleanOptions[i]] = PlusWnd.Button_IsChecked(BooleanOptions[i]); SetBoolOption(BooleanOptions[i], Settings[BooleanOptions[i]]); } } // For the interval Settings['Interval'] = PlusWnd.Combo_GetCurSel("IntervalSec") * 10; Settings['Interval'] += PlusWnd.Combo_GetCurSel("IntervalMin") * 60; Settings['Interval'] += PlusWnd.Combo_GetCurSel("IntervalHour") * 3600; SetStringOption("Interval", Settings['Interval']); // Interval can be too big for Int
// Should the plugin be turned on / off? TurnOn(PlusWnd.Button_IsChecked("IsOn")); } function TurnOn(NewState) { if(NewState == Settings['IsOn']) return;
if(Signin && Settings['ShowToast']) { // Make the user aware of the plugin var sec = Settings['Interval'] % 60; var min = ((Settings['Interval'] - sec) / 60) % 60; var hour = (((Settings['Interval'] - sec) / 60) - min) / 60; MsgPlus.DisplayToast("NickChange Plugin", "NickChange Plugin is still on\r\nInterval: "+hour+"h "+min+"m "+sec+"s\r\nOrder: "+(Settings['IsRandom']?"Random":"Sorted")+"\r\nChange: "+(Settings['ChangePSM']?"Personal Message":"Display Name")); }
// The list of names should be > 0 if(GetAllNames().length < 1) { StandardError("NotEnoughNames"); TurnOn(false); return; } if(Signin && (new Date().getTime() < Settings['LastChange'] + (Settings['Interval'] * 1000))) { // Remember last change MsgPlus.AddTimer("ChangeTimer", (Settings['Interval'] * 1000) - (new Date().getTime() - Settings['LastChange'])); } else { OnEvent_Timer("ChangeTimer"); } Started = true; } function Stop() { if(!SignedIn) return; if(!Started) return; // Cancel the timer MsgPlus.CancelTimer("ChangeTimer"); // Save last change SetIntOption("ChangeNum", Settings['ChangeNum']); SetStringOption("LastChange", Settings['LastChange']); // Too big for DWORD, so use a string to save it // Now not started anymore Started = false; }
function ReadNamesFile() { // For the names list Settings['Names'] = []; var Category = "Default"; Settings['Names'][Category] = []; Categories = []; Categories.push(Category); if(Settings['NameFile'] == null || Settings['NameFile'] == "null" || Settings['NameFile'] == "") { // Save option Settings['NameFile'] = MsgPlus.ScriptFilesPath+"\\"+Settings['UserId']+".txt"; SetStringOption("NameFile", Settings['NameFile']); // Create the new file (for edditing) var NameFile = FileSystem.CreateTextFile(Settings['NameFile'], false, Settings['Unicode']); NameFile.Close(); } else { var NameFile; var thisline; var error = false; var i = 0; try { NameFile = FileSystem.OpenTextFile(Settings['NameFile'], 1, true, (Settings['Unicode']?-1:0)); } catch(e) { error = true; } if(!error) { do { try { thisline = NameFile.ReadLine(); if(thisline.charAt(0) == "[" && thisline.charAt(1) != "[" && thisline.charAt(thisline.length - 1) == "]") { if(thisline.substring(1, thisline.length - 1) != Category) { Category = thisline.substring(1, thisline.length - 1); Settings['Names'][Category] = []; Categories.push(Category); i = 0; } } else if(thisline != "") { if(thisline.charAt(1) == "[") thisline = thisline.substr(1); Settings['Names'][Category][i] = thisline; i++; } } catch(e) { error = true; } } while(!error); NameFile.Close(); } } } function GetAllNames() { var output = []; var cats = Settings['Category'].split(";"); for(cat in cats) { output = output.concat(Settings['Names'][cats[cat]]); } return output; } function CleanCategory(Category) { var cat = ""; for(var i = 0; i < Category.length; i++) { if((/[a-zA-Z0-9 ']/ig).test(Category.charAt(i))) cat += Category.charAt(i); } return cat; } function GetOption(Name) { try { return Shell.RegRead(MsgPlus.ScriptRegPath+Settings['UserId']+"\\"+Name); } catch(e) { return null; } } function SetOption(Name, Value, Type) { Shell.RegWrite(MsgPlus.ScriptRegPath+Settings['UserId]+"\\"+Name, Value, Type); } function GetBoolOption(Name) { return (GetOption(Name) == 1); } function SetBoolOption(Name, Value) { SetOption(Name, Value?1:0, "REG_DWORD"); } function GetIntOption(Name) { return Number(GetOption(Name)); } function SetIntOption(Name, Value) { SetOption(Name, Number(Value), "REG_DWORD"); } function GetStringOption(Name) { var opt = GetOption(Name); if(opt == null) return ""; return String(opt); } function SetStringOption(Name, Value) { SetOption(Name, String(Value), "REG_SZ"); } function PersonalizedStatus() { var myRegExp = /^(.*)(xA0{(.+)})$/ig; return myRegExp.exec(Messenger.MyName); } function In_Array(SearchFor, TheArray) { for(key in TheArray) { if(TheArray[key] == SearchFor) { return key; } } return -1; }
It's JS anyway? o.o.
17-04-2008, 08:32 PM
jackass
@Invent & Blob - Neither of your codes work. It says there is an error or something. Sorry. (+rep anyway! :))
17-04-2008, 08:35 PM
Invent
Quote:
Originally Posted by Movieen
It's JS anyway? o.o.
I know that know (thus my post's edit), at a glance it looked like a dsktp. programming language.
Bio, the code you posted gives me errors, could you please make sure you copied the full code?