[IDEA] plusQuery - 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: [IDEA] plusQuery (/showthread.php?tid=95002) [IDEA] plusQuery by Amec on 07-13-2010 at 04:43 AM
Hello. I was wondering if anyone had thought of making a jQuery-esque library for Messenger Plus! Live. I believe this would make it much easier and quicker to develop scripts, much like jQuery is for web dev. code: I was thinking we could store everything in like an xml data structure, and access it via $(). Like, $("ChatWnd") would select all the ChatWnds, $("ScriptMenu") would select the menu, etc... Or we could do it like $.chatWnd and $.scriptMenu or something... I really don't know atm. Would anyone be interested in working on this with me? Edit: Let me clarify on "we could store everything in like an xml data structure". An example with a LOT of stuff missing: code: One could do $("Contact") to get a Contacts object, or $("Contact > Email:contains('lol')") to get a list of Contacts whose email has 'lol' in it. And this shouldn't just apply to ChatWnds, every data structure (Debug, Messenger, MsgPlus, Emoticons, PlusWnd, Interop, ScriptCommands, ScriptMenu, etc.) should be accessible in this structure, which is updated at run time when data changes... RE: [IDEA] plusQuery by Spunky on 07-13-2010 at 06:29 AM
I like the idea, but it'd be hard to implement I think. Then you either have to ship the file with every script that uses it giving you multiple copies on the same user's PC, or find a way to download it from an online source and execute it into the current script. RE: [IDEA] plusQuery by Matti on 07-13-2010 at 07:55 AM
I've had a similar idea once, mainly because I would love to assign and remove event handlers like in jQuery (with bind() and unbind()). quote:I think such a library shouldn't get much larger than 10 to 15 kB when properly minified. Besides, if it's a good library which really makes scripting easier, the file size doesn't matter that much anyway. RE: [IDEA] plusQuery by CookieRevised on 07-13-2010 at 11:47 PM
quote:... bigger, slower, more prone to errors, very hard to debug, beginning scripters don't even know what they actually are doing (and thus asking more questions as to why something doesn't work), etc.... RE: [IDEA] plusQuery by Matti on 07-14-2010 at 10:28 AM
quote:That's what you could say about any abstraction layer: jQuery, .NET,... The extra file weight shouldn't be so much of a problem for modern computers and Internet connections, nor should the difference in performance be very noticeable if the library creator knows what he's doing. I agree that the use of a framework can make debugging tougher, it adds an extra abstraction layer between developer and machine so the chance that you're doing something wrong may increase. However I think the chance of doing something wrong is bigger when the developer has to write a whole function by himself then when he calls a library function which is already thoroughly tested. You're probably right that beginning developers will tend to jump straight onto a library without learning the underlying language. I didn't learn C++ before C# either so I'm also in that same boat, but I started with JavaScript so I already knew about the basics of programming. I've seen people jump straight into jQuery who don't know anything about the basic structures of JavaScript. This also applies to Plus! scripting on top of JScript: newcomers try to do two things when a message is send, so they define two OnEvent_ChatWndSendMessage functions... Perhaps a library could help here. I understand your worries about using frameworks. Perhaps a better solution would be that the Plus! scripting environment itself gets updated to comply with our needs (I really want better event handling!), so we don't need libraries to give us what the scripting environment can't do. And if that doesn't happen, I could just make a small private framework for my own scripts without releasing it separately. If there's something wrong with the library, then I can still just update my own scripts and don't need to worry about other developers using my library. Note to self: write shorter posts! RE: [IDEA] plusQuery by Amec on 04-06-2011 at 04:34 AM
lol really old post. So uhh... Since no one seemed interested, I decided to do this myself! Although, I did change it a lot from my original suggestion as I became a better ECMAScript "programmer"... RE: [IDEA] plusQuery by Matti on 04-06-2011 at 09:43 AM
That is truly amazing! js code:Another thing I noticed is that you're extending Object.prototype. While this may work just fine in your library when using your version of Object.prototype.forEach, this surely will break a lot of scripts which iterate over plain objects using a standard for...in loop without the Object.prototype.hasOwnProperty check. I think it's better to simply drop the prototype extensions and only extend the static Object. This is not so much of an issue with the Array and String prototypes, as those should never be iterated over with for...in anyway. The thing I miss is (of course) event binding on PlusWnd objects. If this were possible, we could write classes to work with window controls which can bind the necessary handlers to the used window events. Now, I understand that this is very tough to implement and would probably require a lot of hackish constructions. I found a way to inject function in the global object in run-time, but it's very, very ugly. Hopefully the event architecture gets fixed/improved in some future version of Plus!... This deserves its own thread though... RE: RE: [IDEA] plusQuery by Amec on 04-06-2011 at 11:12 AM
quote:Thanks. quote:Hmm, I just tested this... I guess it's something I overlooked. Oops! I'll change them all to the combined getter/setter functions as you suggested soon. quote:Yeah, I realised that was terrible after I started to REALLY understand ECMAScript... Haven't had time to move them from Object to plusQuery yet. And people who don't check for hasOwnProperty while iterating are silly. But... I guess I have to take that into account. quote:Yeah, I thought about it for a bit, and had no idea. The global variable in JScript seems REALLY screwey. Doesn't seem to be a way that I can see which adds properties to it. js code:It would be so much easier if you could just add it to the global variable. How did you manage to do it? RE: [IDEA] plusQuery by matty on 04-06-2011 at 12:46 PM Simply amazing! RE: [IDEA] plusQuery by Amec on 04-06-2011 at 02:07 PM
...oh hey. I just thought of something... It can be done using eval. (feeling kinda sick just by saying that) js code: This would work, no? RE: [IDEA] plusQuery by Matti on 04-06-2011 at 03:03 PM
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.) js code: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. RE: RE: [IDEA] plusQuery by Amec on 04-06-2011 at 04:11 PM
quote:This is REALLY annoying... Surely they could switch to V8 or something? But then they'd have to write their own stuff for accessing ActiveX... Hmm. quote:It's not really "tricking eval"... It's fine, and more clear than just declaring the variables without var. And what happens if there's a variable with the same name in the local scope? (I know that'll almost never happen, but still) Now that I think about it... Wouldn't there be a message to MessengerPlusLive_MsgPump we could send to have the script reevaluated? Not 0x81CE, (restarts all scripts) but something similar? RE: [IDEA] plusQuery by matty on 04-06-2011 at 05:19 PM
One thing I noticed js code:You cannot obtain the Contact object by passing the origin parameter to the GetContact function. RE: [IDEA] plusQuery by Eljay on 04-06-2011 at 06:03 PM
JScript does have a global scope. In regular JScript (WSH) you can just do "var global = this" in global scope then access it anywhere. RE: [IDEA] plusQuery by Matti on 04-06-2011 at 06:11 PM
quote:He extended the GetContact implementation so that you can search by name as well. js code:Still, it's not a good idea to do this. The value of origin may not resolve to the right contact, for example when a contact has a nickname assigned. Contact.Name always returns the name as published by the contact, whereas origin may contain the nickname of that contact. I think it's better to simply use origin - if the developer wants to resolve this to a contact, he can just implement this in the callback or override the event himself. Also, the local command parsing should be a bit more sophisticated. For example, script commands should be escapable by adding an extra leading slash, such as "//mycommand". Also, parameters can be separated by many sorts of whitespace characters such as \n, \r,... Therefore, you'll need a regular expression to properly detect whether a given message is a script command and correctly separate the command from the parameter. Luckily, Cookie has written an excellent regular expression for this: CookieRevised's reply to Gettin data from "/" commands. The way I parse local commands is based upon Cookie's regular expression but instead of using the global RegExp object to retrieve the data, I use the result from exec() itself. It's better to use your local data rather than having to rely on global side effects. js code:This principle can't be easily ported to external commands though, since you don't know what the leading character will be (! or @ or ...). However, you won't have to deal with escaped commands either. I'd recommend to simply look for the command until the first encountered whitespace character and use the remaining part as parameters. js code: quote:I know, I tried that but it's inaccessible. You can't read global variables from it or add variables to it. Heck, you can't even iterate over its contents. Very sad indeed. Long post is long indeed. RE: [IDEA] plusQuery by Eljay on 04-06-2011 at 06:20 PM
Ok I found when/why global scope was broken: Patchou's reply to 300 breaks NP script RE: [IDEA] plusQuery by CookieRevised on 04-06-2011 at 10:27 PM Offtopic sidenote: quote:It's not 'better' though (it isn't worse either for that matter). There is nothing wrong with using the global RegExp object as long as both functions (exec and the resulting global RegExp object) are used right after eachother. But if they are not used right after eachother, then yes, you have a very good point. But also, it is also not a 'side effect' though; the $1 identifiers are meant to be used like that. But, this is just semantics I guess and what you prefer.... On topic, nice to see some advanced 'toying' (if I may use that word) with the scripting engine to create such a library and create such possebilities. But although I'm sure one could come up with an exotic use or examples for it, I must say, I can't see any real use of it in practice, certainly not for the average script and scripter, but also not for the more advanced scripts. But this said, again, great work . RE: [IDEA] plusQuery by Amec on 04-07-2011 at 05:43 AM
quote:Fix'd. Moved all of those functions to plusQuery. quote:Done. quote:Aaaand done! What I haven't done:
quote:Is he planning on fixing it? -_- quote:I find it useful for writing my own small scripts. Here's a recent example: I wanted to add two commands, "/afk" and "/back", which set my name to Messenger.MyName + "\xA0" + status, and back again. Pretty simple, ey? So instead of creating a whole new script for it, I just created a new .js in my "Misc" script which has _plusquery.js, and added it using $.addCommand. Much easier/faster/better(?) than creating a whole new script and doing all the parsing of commands, etc. again. RE: [IDEA] plusQuery by CookieRevised on 04-07-2011 at 09:36 AM Sure, but as for that specific example, that could be done in much easier ways too though I think (as in using a more straightforward library). So, maybe not the best example. But as long as you (and others) find it useful, then |