Nickname highlight - 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: Nickname highlight (/showthread.php?tid=86201) Nickname highlight by Johnny09 on 09-28-2008 at 04:02 PM
Hello community, its okay.. i figured it out myself: -- var highwords = new Array ("johnny", "jay"); function OnEvent_Initialize(MessengerStart) { } function OnEvent_Uninitialize(MessengerExit) { } function OnEvent_ChatWndReceiveMessage(ChatWnd, Origin, Message, MsgKind) { var e = new Enumerator(ChatWnd.Contacts); var contact = e.item(); checkAndDisplay (Message, contact.Name); } function checkAndDisplay (Message, my) { for (i in highwords) { if (Message.toLowerCase().search(highwords[i]) != -1) { MsgPlus.DisplayToastContact("Nick Highlighter", "[c=#3682B4]Highlight[/c]", "'"+ucfirst(highwords[i])+"' has been mentioned by: " + my, null, "locateDetectedAddress"); } } } function ucfirst(str) { return str.substr(0,1).toUpperCase() + str.substr(1,str.length); } RE: Nickname highlight by Spunky on 09-28-2008 at 05:53 PM
code: Should do the same thing, but more efficiently... Could probably be improved upon though. Also, you can add other words into the array apart from names such as words relating to certain topics RE: Nickname highlight by markee on 09-29-2008 at 11:01 AM
An alternative to Spunky's code is to use a regular expression, which would make the code look something like this. code: Or if you didn't want it to list every word that is matched, which was sent in a single message (something like "Spunky SLM" would generate 2 toasts). then you could use the following. code: Also, I should note that the \\b used in the regex means that it must be the whole word (unlike spunky's which will match even "ASLMNDER" or something similar if it were ever to occur). The i modifier allows for the letters to be in upper or lower case, just so that it doesn't matter if your friend types your name in caps for some unknown reason. Obviously you could make the code smaller by writing straight into the regex, however I would recommend keeping the regex as a global variable unless it became contact dependant as this means it only needs to loaded the once. RE: Nickname highlight by Spunky on 09-29-2008 at 11:05 AM Lol. I could have added a space to either side of the word when checking... I should have tested it lol RE: Nickname highlight by markee on 09-29-2008 at 11:22 AM
quote:And what about if it was a comma, or full-stop, or semicolon, or exclamation mark, etc....? RE: Nickname highlight by Spunky on 09-29-2008 at 03:34 PM
quote: RegExp use \W to check that it's not an alphanumeric character before the word. I do agree RegExps are great, but I tried to keep it simple. It's because of you I started using them in the first place RE: Nickname highlight by Johnny09 on 10-03-2008 at 05:26 PM
yeah, regexp is also a good solution, code: |