What happened to the Messenger Plus! forums on msghelp.net?
Shoutbox » MsgHelp Archive » Messenger Plus! for Live Messenger » Scripting » [IDEA] plusQuery

[IDEA] plusQuery
Author: Message:
Matti
Elite Member
*****

Avatar
Script Developer and Helper

Posts: 1646
Reputation: 39
32 / Male / Flag
Joined: Apr 2004
RE: [IDEA] plusQuery
The solution I came up with also uses eval() as there's no global object in JScript which stores the global variables. (In browser JavaScript, there's the global object "window" which holds the global scope.)
However, you'll have to do one extra thing to make it work...

When adding globals using eval() in run-time, the scripting engine will not register those added functions as event handlers. That is, if you add an OnWndIdEvent_Destroyed() event using eval(), it won't get called when the window is destroyed. The trick to get these registered is to use MsgPlus.LoadScriptFile(). When calling LoadScriptFile, the script file is loaded and the global scope is rescanned for event handlers. This results in the newly added functions to be properly registered. :)

Note that you don't need to trick eval() to be called in the global scope. By simply omitting the "var" keyword, the variable will be created in the global scope. It is generally a bad idea to omit the "var" keyword, but in this case it's sort of acceptable. :P

Proof of concept:
js code:
var plusWnd = $(MsgPlus).CreateWnd("interface.xml", "yiew", 0);
//[...]
$.wrappers.MsgPlus.CreateWnd = function (XmlFile, WindowId, Options) {
    var toEval = "On" + WindowId + "Event_Cancel = function (plusWnd) { $.trigger(plusWnd, '" + WindowId + "Event_Cancel', plusQuery.$A(arguments)); };";
    toEval += "On" + WindowId + "Event_Destroyed = function (plusWnd, exitCode) { $.trigger(plusWnd, '" + WindowId + "Event_Destroyed', plusQuery.$A(arguments)); };";
    //etc
    eval(toEval);
    $(MsgPlus).LoadScriptFile("_blank.js"); // black magic happens here

    this.original.CreateWnd(XmlFile, WindowId, Options);
}
The loaded script file can contain anything. From my tests, it may not be completely empty though - one character will work though. I think the best options to fill this file with are a single space " " or a semicolon ";". You can even save it as ANSI and save a few bytes, Plus! will still parse it (although Plus! recommends Unicode).

I warned you, it's very hackish and not really recommended (eval is evil but so is LoadScriptFile) but unfortunately it's the only way I could get this to work. Feel free to use it if you think it's "good enough" but think about the consequences. If you decide to use this, don't forget to keep track of the created event handlers so you don't need to redeclare them when creating the same window twice. :P

This post was edited on 04-06-2011 at 03:05 PM by Matti.
Plus! Script Developer | Plus! Beta Tester | Creator of Countdown Live | Co-developer of Screenshot Sender 5

Found my post useful? Rate me!
04-06-2011 03:03 PM
Profile E-Mail PM Web Find Quote Report
« Next Oldest Return to Top Next Newest »

Messages In This Thread
[IDEA] plusQuery - by Amec on 07-13-2010 at 04:43 AM
RE: [IDEA] plusQuery - by Spunky on 07-13-2010 at 06:29 AM
RE: [IDEA] plusQuery - by Matti on 07-13-2010 at 07:55 AM
RE: [IDEA] plusQuery - by CookieRevised on 07-13-2010 at 11:47 PM
RE: [IDEA] plusQuery - by Matti on 07-14-2010 at 10:28 AM
RE: [IDEA] plusQuery - by Amec on 04-06-2011 at 04:34 AM
RE: [IDEA] plusQuery - by Matti on 04-06-2011 at 09:43 AM
RE: RE: [IDEA] plusQuery - by Amec on 04-06-2011 at 11:12 AM
RE: [IDEA] plusQuery - by matty on 04-06-2011 at 12:46 PM
RE: [IDEA] plusQuery - by Amec on 04-06-2011 at 02:07 PM
RE: [IDEA] plusQuery - by Matti on 04-06-2011 at 03:03 PM
RE: RE: [IDEA] plusQuery - by Amec on 04-06-2011 at 04:11 PM
RE: [IDEA] plusQuery - by matty on 04-06-2011 at 05:19 PM
RE: [IDEA] plusQuery - by Eljay on 04-06-2011 at 06:03 PM
RE: [IDEA] plusQuery - by Matti on 04-06-2011 at 06:11 PM
RE: [IDEA] plusQuery - by Eljay on 04-06-2011 at 06:20 PM
RE: [IDEA] plusQuery - by CookieRevised on 04-06-2011 at 10:27 PM
RE: [IDEA] plusQuery - by Amec on 04-07-2011 at 05:43 AM
RE: [IDEA] plusQuery - by CookieRevised on 04-07-2011 at 09:36 AM


Threaded Mode | Linear Mode
View a Printable Version
Send this Thread to a Friend
Subscribe | Add to Favorites
Rate This Thread:

Forum Jump:

Forum Rules:
You cannot post new threads
You cannot post replies
You cannot post attachments
You can edit your posts
HTML is Off
myCode is On
Smilies are On
[img] Code is On