Github Address Bar Search Firefox Add-on

A couple of weeks ago Mozilla Labs & Twitter released a restartless Firefox add-on called "Twitter Address Bar Search", which actually did 3 main things:

  1. Added a app tab for http://twitter.com/ if you did not already have one.
  2. Added a Twitter search engine.
  3. Added results to the address bar's suggestion list for you when you typed @username of #hash, which would allow you to save time whilst searching for @mentions or #hashes

Then Dietrich partly ported the address bar mods to a add-on sdk module. So I took his module, made some improvements, fixed some bugs, and whipped up a extension that does basically the same thing as the "Twitter Address Bar Search" add-on, but for Github, and made with the add-on sdk.

Github Address Bar Search

The "Github Address Bar Search" add-on is the same as the "Twitter Address Bar Search" add-on, except it doesn't add a Github search engine, I leave that to you.

Restartless Firefox Add-ons, Part 6: Better Includes

I just wanted to make a quick update on part 2: includes, because I've written a better include() function. This one will allow you to include files at any point in your bootstrap.js file; so you no longer need to wait for the startup function to run, and you no longer need to use the AddonManager.jsm file. This is just much more simple.

Just copy & paste the script above into your bootstrap.js file and then any code executed after it can use it immediately, and with relative urls. This is why you no longer need to use the AddonManager.jsm file, and that is why you no longer need to wait to use the startup method before including helper files.

Scriptish 0.1 Released!

Well, I'm very proud to announce that Scriptish 0.1 has finally been released!

Thank you

This is an event that has taken a long time to achieve, and I have had so much help from so many wonderful people that it has been a great pleasure to work on this project.

Greg Parris

Greg forked Scriptish and started contributing back in Oct '10 and he's been a constant help ever since. Greg has written plenty of code, made the wiki readable, improved the usability and user experience, and no doubt has spent countless hours testing. Thank you Greg!

Olivier Cornu

Olivier really showed me the way, he had forked Greasemonkey long before I ever started Scriptish, making a extension called Webmonkey which used Firefox 3 as the minimum supported version and taking advantage of the benefits that Firefox 3 had to offer. I pulled some code from Webmonkey and made Olivier the author (which he told me would be alright), but he really provided me with a proof by example of a simple idea, that a far better user script engine could be made by increasing the minimum supported version and taking advantage of the new features. Thank you Olivier!

Kirs Maglione

Kris has helped out with some error handling contributions early on, answering more than a few of my questions on IRC, and for doing the last few reviews on AMO which I'm sure took some time. Thank you Kris!

Nils Maier

Nils wrote some wonderful commits revamping the install window and really improving the UX of user scripts in the extension manager. I think these changes are the most visible to the average user, and are great improvements imo, so his help has been invaluable. Thank you Nils!

Dave Townsend

Dave is one of the developers of the new Addon Manager in Firefox, and he made a restartless extension called SlipperyMonkey (which he blogged about here) showing off a bunch of Firefox 4's new features. I've pulled a lot of this code in to Scriptish, and had the pleasure to meet Dave at the 2010 Mozilla summit in Whistler when he was showing SlipperyMonkey off, and got a change for a quick ~5min QA which proved to be most helpful to me. Thank you Dave! (and thank you David Dahl for telling me to speak with him, which I might not have done).

Mozillians

A community really makes all of the difference, and I've met no better. Just look at the documentation, look at the support, look at the inspiration, and look at the goals. Thank you Mozillians!

Github

I quite honestly wouldn't have bothered spending so many unpaid hours managing a open source project without a site that helps me administrate it like Github does, because it'd just be a waste of time. Thank you Github!

Restartless Firefox Add-ons, Part 5: Logging

This is a simple one for most of you, but I found someone asking the question "How do I dump messages from bootstrap.js" on stackovercrap so I thought it would make a good topic to quickly blog about.

First of all what I'm about to describe is exactly how one would log messages and report errors from a JavaScript code module, so if you already know how to do this, then stop reading and bounce.

If you are lost without window.dump or don't know what that is, then give this page https://developer.mozilla.org/en/window.dump a quick read. There is a note that says:

"dump is commonly used to debug JavaScript. Privileged code can also use Components.utils.reportError and nsIConsoleService to log messages to the Error Console."

Bingo! Give the page on nsIConsoleService a re-read. There is a code example on the top of that page that you can use to get a console service, then the page describes it's various methods, such as logStringMessage. You can use the logStringMessage method in window.dump's stead.

The window.dump page also mentioned Components.utils.reportError which can be used for logging error messages to the Error Console.

The way that I prefer to access the console service is via the Services.jsm JavaScript code module, like so:

Components.utils.import("resource://gre/modules/Services.jsm");
Services.console.logStringMessage("this is a console message, look for it in the messages tab of the Error Console.");

Restartless Firefox Add-ons, Part 4: Localization (l10n)

Alright, part four has been a long time coming, but I finally got around to typing out an localization include for restartless Firefox 4 addons which I'm ready to talk about. If you haven't read part 2 it's all about how to use includes, so read it first, if you don't know what a restartless addon is, then start with part 1.

To start off with I wrote this include for Restartless Restart, and I consider that to be my demo.

Overview

Alright, so you should know how to use includes in a restartless addon now, and I shouldn't have to explain why localizing your addon is important, and you have an example; here are some notes:

To begin with you will need to copy this l10n.js file in to your addon, then include it at startup (in your addons bootstrap.js file) and create the all important underscore function (literally "_(aKey)"), like so:

Setup

function startup(data) AddonManager.getAddonByID(data.id, function(addon) {
include(addon.getResourceURI("includes/l10n.js").spec);
l10n(addon, "filename.properties", "en-US");
}

So the example above assumes that you copied the l10n.js into a includes/ subdirectory, and that "filename.properties" is the name of the files within a /locale/en-US/ subdirectory for example, so the path to the english (US) translation for the text in your addon would be "/locale/en-US/filename.properties" (I would recommend using something other than "filename"). After l10n() is called it will create (and return) a global function named "_", which can be used to obtain the appropriate localized text. The 3rd parameter for l10n is the default locale that should be used when all other attempts fail. A failed attempted could be caused by a missing locale file (say you haven't yet translated your addon for the user's locale for instance), or the locale file could exist but not have the requested key, or the key could exist but be blank.

Using _

_ takes 2 arguments aKey, and aLocale which is optional.

aKey is the key for the text in your .properties file.

aLocale allows you to attempt to grab a specific translation before trying to get a translation from the user's locale, and lastly trying the default locale specified by the addon developer in the l10n call above (if that 3rd argument of l10n isn't provided then "en" is used). I use this in Restartless Restart to provide the user with the ability to override their browser's locale and get another translation. So I use the ja-JP translation for Restartless Restart on my Firefox profiles these days just because.

Conclusion

If you have a restartless addon, and you haven't localized it yet, then get to it!

Restartless Firefox Add-ons, Part 3: Icons

Well this is only part three, we are still just getting started after all =] so since I have very little time today I thought that I would write about how to include a icon for your restartless extension, since it's not exactly obvious. Although this method is documented here.

Basically all you need to do is include a icon.png in the root of your xpi (the same place as your bootstrap.js and install.rdf) and Firefox will automatically find it. You can also include a icon64.png in the root of your xpi and this will be used in the add-on manager's add-on detail view, so it's a good idea to include both if you have them because it'll be a better UX.

If you want to use the icon in other places use the method that I described in part 2 in order to find the file: url of the image and use that.

Google Reader Widget + Panel Jetpack for Firefox 4

I was doing a little hacking on the Add-on SDK a few weeks ago and whipped up a simple add-on for Google Reader which demonstrates a typical use case for the widget and panel modules which are part of the addon-kit package which comes with the Mozilla Add-on SDK. I call this add-on GReader Panel, and it basically just creates a clickable widget (which is just an icon that you can put anyplace that a toolbar item can go), which when clicked will open/close a panel about the size of a iPod screen with Google Reader mobile.

Check it out on AMO!

If you're interested in seeing the code, it's available on Github like all of my open source work.

Restartless Firefox Add-ons, Part 2: Includes

Today I'm going to write about including files into your bootstrap.js file's scope. There are a few different types of files that you'll want to include, and I'm only going to talk about three of them today, importing javascript modules provided by Firefox or other extensions, and including (using loadSubScript) files packaged with your add-on, or any other.

Importing Modules

This is pretty simple, Components is available, so Components.utils.import is available. So import javascript modules like so:

Components.utils.import("resource://gre/modules/Services.jsm");

Note: I highly recommend reviewing the Services.jsm module, it's a handy one.

Includes

There are many reasons why you'd want to access other files packaged with your add-on, one of them being if your bootstrap.js file starts getting large then you'll probably want to break that code up in to multiple files and include them in the bootstrap.js file. Another would be if your add-on needs to get the file location of a image or some other asset packaged with the add-on.

In order to figure out the location of files packaged with an add-on, the AddonManager.jsm & Services.jsm module will be needed, import it with the following code:

Components.utils.import("resource://gre/modules/Services.jsm");
Components.utils.import("resource://gre/modules/AddonManager.jsm");

Then add the following implementation of a include function:

/* Includes a javascript file with loadSubScript
*
* @param src (String)
* The url of a javascript file to include.
*/
(function(global) global.include = function include(src) (
Services.scriptloader.loadSubScript(src, global)))(this);

Now in you'll want to call AddonManager.getAddonByID() with the add-on's id, which you can get from the bootstrap.js file's startup method's data param, like so:

var img;
function startup(data) AddonManager.getAddonByID(data.id, function(addon) {
// Include some utility functions
include(addon.getResourceURI("includes/utils.js").spec);
// Remember some image's url
img = addon.getResourceURI("images/star.png").spec;
});

I should be blogging about some includes which'll make developing restartless add-ons much easier in following posts!

Status Update: Week 44

Done

Restartless Restart

The main event for me this week was releasing Restartless Restart, which is a very tiny and restartless add-on which adds a "Restart" menu item to the "File" menu and a restart hotkey (ctrl/cmd+alt+r) to Firefox or Seamonkey. I hope you like it!.

Thanks to supahgreg for the Windows 7 patch!

Scriptish

  • Supporting various headers introduced by IE Scripts: @injectframes, @defaulticon, and @website.
  • Made a few bug fixes for Seamonkey related to the toolbar. I'm going to need to spend more time testing + planning this before the next release though, because I'm not sure if Seamonkey will be using a add-on bar or not yet, I assume they will and just haven't yet, but I'll plan for now as though they won't.
  • Implemented GM_safeHTMLParser(aHTMLStr) (issue #113).
  • Reviewed and merged update from supahgreg to add a optional "Copy Download URL" menu item to user scripts in about:addons (issue #79).

Mozilla Labs: Prospector

  • Fixed a couple of things that caused warning messages.
  • Small patch for Instant Preview so that it doesn't check for url bar selections while the url bar suggestion pop up is closed (issue #24).
  • Changed the click handler for suggestions from Find Suggest so that if you click a suggestion that is the same as your query (which it is after the first time you click a suggestion), then that triggers the next button (issue #32).

[More]

Restartless Restart Add-on for Firefox

I've always wished that Firefox had a "Restart" menu item, and because of that I've used the Quick Restart Firefox add-on quite a bit in the past. At some point last year while the Jetpack prototype was still being developed I even wrote a jetpack to add the menu item in less than 50 lines for a contest that Mozilla had. I used that for a while, but these days I live on the FIrefox nightly (aka Minefield) and both of those old options aren't available to me any longer. So I decided to write a restartless add-on to add a "File" -> "Restart" menu item to Firefox.

I'm calling this add-on "Restartless Restart" and it works on FIrefox 4+, it's 1KB at the moment, and it does not require a restart to be enabled, disabled, installed, or uninstalled. You can find it on addons.mozilla.org here. If you want to contribute, then you can find the project on GitHub, where all of my projects can be found.

The part that I love most is that it's still less than 50 lines =]

More Entries

© Erik Vold 2007-2012. Contact Erik Vold. Top ^