Jérôme Belleman
Home  •  Tools  •  Posts  •  Talks  •  Travels  •  Graphics  •  About Me

JavaScript Tricks for Pentadactyl

9 Feb 2013

As I wrote plugins for Pentadactyl, I learned about by practice about some JavaScript tricks which are specific to this overwhelmingly good Firefox add-on.

I struggled to find my way in the JavaScript API. While most of the time you can and probably should get away with plain JavaScript, it can be useful to use some of the higher-level functions defined in Pentadactyl.

1 Useful Functions and Objects

Using the javascript command, you will get to come across some useful functions and namespaces such as:

2 The Buffer Module

The buffer module lets you work with buffers which, in essence, are tabs (see :help buffer).

3 Development and Debugging

As explained in :help starting, you can use the :rehash command to have Pentadactyl reread everything, which is useful when you're in the development/testing loop.

The services.console.logStringMessage() function occurring in common/content/dactyl.js writes messages to the console. For some reason it doesn't always seem to work. You can also conveniently use the plain JavaScript throw "oops" to display error messages in the status bar.

4 More Information

You may want to have a look at the function definitions and their usage in the Pentadactyl source itself:

Generally speaking, if you want to find out which functions is called for a particular command, you can try to:

  1. Look it up in :help to find the canonical name for the command: e.g. :help gg is <scroll-top>.
  2. Go grep for the canonical name in the Pentadactyl source: e.g. grep -r '<scroll-top>' *.
  3. Find out how the mapping is defined for this command and which function is called: e.g. <scroll-top> triggers a scrollToPercent().