Chickenfoot for Firefox: Rewrite the Web

User Interface Design Group

Libraries

What is a library?
Using a library in a script
Libraries that are provided with Chickenfoot
How to create your own library

What is a library?

Though we have tried to provide a comprehensive set of commands with Chickenfoot, we know that we may not have everything you need. However, we also provide an include() command that lets you include Chickenfoot code from other files so that you can take advantage of code that others have written. Such a reusable file is called a library, and we have packaged several libraries (discussed below) with Chickenfoot. We have also allocated space on the Scripts Wiki for users to upload their own libraries, so you should also look there to see if someone has written code that solves the problem that you're facing.

The files listed below are libraries that are packaged with Chickenfoot. Once Chickenfoot is installed, you can look at the code for each file from your browser. For example, to view the code for google-search.js, enter the following URL into your browser: chrome://chickenfoot/content/libraries/google-search.js.

Using a library in a script

To include one of the libraries that is bundled with Chickenfoot, you need only pass the name of the library file to include() and then you can use the commands defined in the library in your script:
include('google-search.js');
getGoogleSpellingSuggestion('aple'); // returns apple
To include a file on your computer, supply the full path of the file to Chickenfoot:
include("c:\\myscripts\\some-library.js");

Libraries that are provided with Chickenfoot

Currently, we only provide a handful of libraries with Chickenfoot, but we are eager to include more! We imagine that many users would like to have accesss to an AJAX toolkit from inside Chickenfoot, no? Or how about a standard set of functions to manipulate Gmail so that you can create your own Gmail hack without having to start from scratch? If you have library code that you would like to contribute, please post it on the Libraries section of the Scripts Wiki.

closure-lite.js [Learn more]
Closure Lite is a single JavaScript file that contains the core APIs of the Closure Library. To see which Closure APIs it includes, see the official API documentation.
greasemonkey.js [Learn more] [Source code]
Greasemonkey is a popular Firefox extension that is similar to Chickenfoot -- both Greasemonkey and Chickenfoot let you create scripts that you can run on web pages to automate them or change their behavior. Greasemonkey has its own API, so we provide a partial* implementation of the Greasemonkey API so that you can run a Greasemonkey script in Chickenfoot simply by adding the line include("greasemonkey.js") to the top of the script. Although our current implementation of the API is not perfect, many of the Greasemonkey scripts hosted on userscripts.org do not rely on the API at all, so they will likely work "as-is" when run in Chickenfoot.

*The implementation of the Greasemonkey API that is bundled with Chickenfoot is admittedly imperfect -- we would welcome support from the Greasemonkey community to improve it so we can bundle a more complete version with Chickenfoot.

google-ajax-search.js [Learn more] [Source code]
The Google AJAX Search API is "an experimental API that lets you integrate a dynamic Google search module into your web pages so your users can mash up Google search results with other content on your site or add search results clippings to their own content." After you register for a license key, you can use the Chickenfoot wrapper for the API to add search results to any web page.
json.js [Learn more] [Source code]
A JavaScript serialization/deserialization library that optionally outputs to JSON (http://www.json.org/). The library also has a non-strict mode that allows some additional JavaScript types to be serialized that are not permitted in JSON, such as Functions, RegExps, undefined, Infinity, and NaN.

Another option is to include Closure Lite and then use the goog.json.parse and goog.json.serialize functions provided by that library. Newer versions of Firefox can use the built-in JSON object and its methods: JSON.parse and JSON.stringify.

prototype.js [Learn more] [Source code]
Prototype is "a JavaScript framework that aims to ease development of dynamic web applications." It adds helpful methods to built-in types (String, Array, Number, Element, and Event), as well as contributing new components, such as Ajax and Enumerable. The script.aculo.us AJAX library is built on top of Prototype.
scriptaculous.js [Learn more] [Source code]
script.aculo.us is an AJAX library that provides support for adding visual effects, drag-and-drop, and other controls to your web pages. We have tweaked the library slightly to provide better integration with Chickenfoot.
us-geocoder.js [Learn more] [Source code]
Provides access to US geocoding data from http://geocoder.us/.

How to create your own library

TODO: Explain how to avoid clogging the global namespace and how to make loading a library idempotent.


©2004-2008 Massachusetts Institute of Technology