quote:
On Today at 02:07 AM, markee wrote:Sorry, but this is the one time where I think you need to REALLY fix up your code (especially if I'm fixing up your mistakes :\)
I don't see you publicly fixing anything but regardless here it is!
code:
/* define a variable for the original psm */
var oldPSM;
function OnEvent_Initialize(MessengerStart){
try {
/* try and record the old psm */
oldPSM = Messenger.MyPersonalMessage;
/* get a quote */
GetQuote();
/* an error will be caught likely because the user isn't signed in */
} catch ( (err) {}
}
function OnEvent_SigninReady(sEmail) {
/* call the initialize function once the user has signed in */
OnEvent_Initialize(true);
}
function OnEvent_Signout() {
/* try and set the original psm, if this fails we will catch it, likely because of an internet disconnect */
try { Messenger.MyPersonalMessage = oldPSM; } catch ( (err) {}
}
function OnEvent_Uninitialize() {
/* if the script is being uninitalized called the signout function to set the old psm */
OnEvent_Signout();
}
function OnGetScriptMenu(nLocation){
/* add a menu item in case the user wants to get another quote */
return '<ScriptMenu><MenuEntry Id=\'Quote\'>Get new quote</MenuEntry></ScriptMenu>';
}
function OnEvent_MenuClicked(sMenuId, nLocation, oChatWnd){
/* get a quote because the user wants one */
GetQuote();
}
function GetQuote() {
/* declare the url to get the quote from */
var url = 'http://www.quotedb.com/quote/quote.php?action=random_quote_rss';
/*
clear the previous cache of the url
better to not fill up the cache with useless entries markee
*/
Interop.Call('wininet.dll', 'DeleteUrlCacheEntryW', url);
/* create our xml object */
var xml = new ActiveXObject('Microsoft.XMLDOM');
/* set the async flag to true to prevent hanging messenger */
xml.async = true;
/* load the url */
xml.load(url);
/* define our callback function */
xml.onreadystatechange=function() {
/* if the xml is finished processing the request */
if (xml.readyState === 4) {
/* define a variable for our new psm with the quote - author */
var xpath = '//rss/channel/item/';
var myNewPSM = xml.selectSingleNode(xpath+'description').text+' - '+xml.selectSingleNode(xpath+'title').text;
/* set our xml object to null */
xml = null;
/* if the psm is greater then 129 get a new one, messenger will only show 129 */
if (myNewPSM.length > 129) GetQuote();
else {
/* display the new psm to the user and ask if they want to use it (Yes), get another (No) or stop the process (Cancel) */
switch (Interop.Call('user32', 'MessageBoxW', 0, Messenger.MyEmail+':\n'+myNewPSM, 'Use this quote?', 35)){
/* MB_YES */
case 6: Messenger.MyPersonalMessage = myNewPSM; break;
/* MB_NO */
case 7: GetQuote(); break;
}
}
}
}
}