Keyword Bookmarks with Multiple Parameters

If you have ever looked at the properties of a bookmark, you might have seen the “Keyword” field. This is a very powerful field and makes your life easier. If you already use this field, you may have been disappointed that you cannot add multiple parameters to a keyword, since there is only one placeholder “%s”.

Inspired by the FileIt page, I wanted to create a bookmark keyword that allows me to pass in product and component for filing a new bug. Javascript to the rescue! All you need to do is to take the following code snippet and create a new bookmark as described on the Bookmark Keywords page. You might want to compress the bookmarklet using a site like jscompress.com.

(function(){
  /* First, split the passed string. You may use any delimiter you want, I chose "/" */
  var pc = "%s".split("/");
  /* Now set the base URL for the target to visit */
  var target = "https://bugzilla.mozilla.org/enter_bug.cgi?rep_platform=All&op_sys=All";
  /* If at least one parameter was passed, then add it as the product */
  if (pc.length) target += "&product=" + pc[0].charAt(0).toUpperCase() + pc[0].substr(1);
  /* If at least two parameters were supplied, then add the second as the component */
  if (pc.length > 1) target += "&component=" + pc[1].charAt(0).toUpperCase() + pc[1].substr(1);
  /* Now go to the target location */
  document.location.href = target;
})();

Afterwards, you can directly use the bookmark using the address bar:

" fileit calendar/alarms "

About these ads

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s