Wednesday, January 3rd, 2007

Using YUI in GreaseMonkey Scripts

Category: Yahoo!

Carlo Zottmann, a Yahoo! engineer in Munich, is a fan of GreaseMonkey and wanted to use YUI in his user scripts.

His article provides a reusable model for how to make use of YUI in the GM script without stomping on any YUI use already on the page:

In this brief article, I’ll share with you my own effort to reach that goal — a Greasemonkey script that adds calls to external JavaScript libraries and CSS files to a given page and, once they are loaded, passes the YAHOO global object to the code inside the Greasemonkey script. (All YUI components reside within this single single global variable, YAHOO — so, for example, you access the YUI Event Utility by referencing YAHOO.util.Event.) I’m sure that this approach is neither the perfect nor the only solution to achieving YUI/Greasemonkey integration, so suggestions and ideas are welcome! Please sound off in the comments and let me know what approaches you’ve taken to this problem in your own projects.

The example script in action: The Greasemonkey script loads YUI components, sends selected text to Yahoo! Babelfish for translation, then displays the results in a YUI Panel Control.

Posted by Dion Almaer at 11:47 am

3.6 rating from 29 votes


Comments feed TrackBack URI

Comment by Patrick Mueller — January 3, 2007

Why isn’t YUI listed on the RESOURCES page of ajaxian?

Comment by Steve Nolte — January 5, 2007

Leave a comment

You must be logged in to post a comment.