check whether if the contact is in a special list? - Printable Version -Shoutbox (https://shoutbox.menthix.net) +-- Forum: MsgHelp Archive (/forumdisplay.php?fid=58) +--- Forum: Messenger Plus! for Live Messenger (/forumdisplay.php?fid=4) +---- Forum: Scripting (/forumdisplay.php?fid=39) +----- Thread: check whether if the contact is in a special list? (/showthread.php?tid=94920) check whether if the contact is in a special list? by ultimatebuster on 07-01-2010 at 10:24 PM
Is this a good way check if a contact is in a trusted list? code: RE: check whether if the contact is in a special list? by djdannyp on 07-01-2010 at 10:38 PM What would the purpose of this trusted list be? RE: check whether if the contact is in a special list? by ultimatebuster on 07-01-2010 at 10:55 PM
some evil purpose that you shouldn't know about RE: check whether if the contact is in a special list? by Matti on 07-02-2010 at 10:05 AM
Your code isn't too bad actually, however it can indeed be optimized. It's better to store your trusted emails in an array rather than a comma-separated string. This also allows you to loop over the array instead of the chat contacts. js code:First, the used variables are declared at the top: i is the index iterator and item is the item iterator. The while-condition combines the iterating (incrementing i and assigning item to the i-th array element) and checking the array length (if i exceeds the array's length, item will be undefined and thus the condition is false), making it one of the fastest ways to loop through arrays in JScript. Note that this only works for arrays where each element equals true, your array can't contain zero, false, null, undefined or empty strings. Inside the loop, we try to find the current item in the Contacts object using GetContact(). This function returns a Contact object when the passed email is in the list, and null otherwise. Thus, to check whether the trusted email is in the chat, we simply have to see if the return value is not null. If it's not null, it means the trusted email is in the chat and thus we should return true. As you can see, this optimizes the function by reducing the work on the JScript side. Your original code loops through all contacts in the chat and then performs an indexOf operation to see if the current chat contact is in the trusted emails list. This code loops through all trusted emails and calls a Plus! function to see if the current trusted email is in the chat contacts list. By changing the looped list, we can let Plus! do some of the work for us, which is probably much faster than any script code you write. RE: check whether if the contact is in a special list? by ultimatebuster on 07-02-2010 at 02:11 PM
Interesting.. RE: check whether if the contact is in a special list? by Matti on 07-02-2010 at 06:24 PM
quote:That may be the case for an Array.indexOf() implementation (which is not available in JScript), but String.indexOf() looks for substrings in a search string. It first has to find the first substring character in the search string and then check whether the other characters are also there, or look elsewhere. To find an item in an array in JScript, we need to rely on loops as there's no such function provided by the Windows Script Engine. RE: check whether if the contact is in a special list? by ultimatebuster on 07-02-2010 at 06:51 PM ah, thank you. |