Thats just what I did. Something like this is so much better and managable.
js code:
var oQuotes = {};
function OnEvent_Initialize(bMessengerStart) {
var xml = createXml();
if ( typeof xml !== 'object' ) return false;
xml.load('quotes.xml');
var quote = xml.selectNodes("/chucknoris/quote");
for(i=0; i<quote.length; i++){
oQuotes[i]=quote.text;
}
}
function OnEvent_ChatWndSendMessage(ChatWnd, Message){
switch (Message.toLowerCase()) {
case "/chuck":
return "[c=green]"+oQuotes[Math.floor((oQuotes.length)*Math.random())]+"[/c] ";
break;
}
}
function OnGetScriptCommands(){
return '<ScriptCommands><Command><Name>chuck</Name><Description>Sends a Chuck Norris sentence</Description></Command></ScriptCommands>';
}
function OnEvent_MenuClicked(MenuItemId, Location, OriginWnd){
if(MenuItemId=="ym"){
OriginWnd.SendMessage(OnEvent_ChatWndSendMessage(OriginWnd, "/chuck"));
}else if(MenuItemId=="about"){
WndAbout = MsgPlus.CreateWnd("WndAbout.xml","WndAbout");
}
}
function OnGetScriptMenu(nLocation){
var ScriptMenu = "<ScriptMenu>";
if(nLocation === MENULOC_CHATWND){
ScriptMenu += "<MenuEntry Id='ym'>chuck</MenuEntry>";
ScriptMenu += "<Separator/>";
}
ScriptMenu += "<MenuEntry Id='about'>About</MenuEntry>";
ScriptMenu += "</ScriptMenu>";
return ScriptMenu;
}
function createXml() {
try {
var xml = new ActiveXObject('Microsoft.XMLDOM');
xml.async = true;
} catch(e) {
try {
var xml = new ActiveXObject('MSXML2.DOMDocument');
xml.async = true;
} catch(e) {
return false;
}
}
return xml;
}
xml code: