Enhance Facebook Notes with Greasemonkey

Web April 27th, 2008

The UI of Write a New Note of Facebook is quite straightforward and … shabby:

The UI of Write a New Note in Facebook


If you happen to use Firefox, this userscript would make Facebook’s notes suck less.

Screenshot

The UI of Write a New Note in Facebook


Requirement

Usage
Exactly the same as WordPress’s quicktags, — no wonder, the core functionality is a port from WordPress’s quicktags.js:

  • You may click to button to start a tag, type some words, then click button again to close the tag.
  • Select the words, and click the button to surround it with the corresponding tag.

License
This piece of script is released under the GNU General Public License as WordPress, a compatible license would make my life much easier.

Development
The development is a little bumpy than my expectation. The biggest obstacle in the way is the namespace in Greasemonky is not consistent to the general DOM model. When the page is loaded, GM takes control, we may manipulate the DOM nodes using various ways. When it is done, all the object in GM’s anonymous global namespace runs out of the scope, and they are garbage-collected.

For every rule, there is an exception: the closure as documented in the bible. The anonymous function would create a closure that wraps a function in the GM’s namespace. However this does not work for us since we need to maintain several records to bookkeeping the status. So eventually we have to inject the scripts and objects into the host. Here is a tip to inject the functions, but for the Javascript objects, we have to manually do the dirty work, error-prone and tedious. If you have a better idea to access the objects that resident in the GM namespace, please leave a comment here.

XPath is awesome !

Web July 29th, 2006

I am really annoyed by the huge images in some linuxfans users’s signatures when surfing the forum, so I decided to hack a user script using Greasemonkey before the moderators of the forum takes any actions.

The XPath is really powerful to manipulate the HTML DOM tree. The signature image is in the the last span element with class attribute equal to postbody in the td element:

allElements = document.evaluate(
    "//td/span[@class='postbody'][last()]/img",
    …

You can download this user script from here. Of course, you need to install Firefox and Greasemonkey first.

Google Transit released

Web December 8th, 2005

Google always give us some surprise, a new service named Google Transit has been released in beta test. With open API for Google Maps, nothing but your imagination stops you building creative applications.

Here is a wild idea to create the GPS application using Google maps:

  1. Build an Firefox plugin/standalone web server to communicate with GPSd, convert the NEMA format data to standard XML data source
  2. Inject the Javascript to Google Maps webpage with GreaseMonkey plugin, which would fetch the data from the plugin/webserver, and show the current position in the map.

Update: here is the application powered by greasemonkey.

More advanced features in mind:

  • Cache Google map meta data and reuse it when offline.
  • Voice navigation