Conkeror: Webjump Helper

0

I’ve finally picked up the Conkeror browser – the keyboard-centric browser that has Emacs like key bindings and is based upon the Firefox html engine – and it’s simply awesome! I hardly ever have to touch the mouse anymore when browsing the web. You should definitely check it out!

I’m not covering the ins and outs of the browser in this post, though. This article is only about Webjumps and an easier way to create them.

By default you need to add a define_webjump for each webjump that you create. Not bad if you only have a couple, but a real pain in the butt if you have hundreds. I solved this issue by defining my webjumps as a dictionary of objects, then passing that dictionary to a function I wrote called makeWebJumps which does what you’d expect – cycle over the dictionary and create each webjump.

Here’s the definition of the function:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
/*
 * takes a list of objects and turns them into webjumps
 * spec is mandatory and can be a url or a function that returns a url, alt is optional
 */
makeWebJumps = function(listOfObjects) {
  for (var i = 0; i < listOfObjects.length; i++) {
    var myWebJumps = listOfObjects[i];
    for (key in myWebJumps) {
      if (!myWebJumps[key].hasOwnProperty('alt')) {
        define_webjump(key, myWebJumps[key].spec);
      } else {
        define_webjump(key, myWebJumps[key].spec, $alternative = myWebJumps[key].alt);
      }
    }
  }
}

And to see how I populate my dictionaries and use makeWebJumps check out the snippet below:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
var baseWebJumps = {
  "wowhead":{spec:"http://www.wowhead.com/search?q=%s"},
  "homemail":{spec:"https://mail.google.com/mail/u/1/#inbox"},
  "yts":{spec:"http://yts.re/browse-movie/%s/720p/All/0/latest", alt:"http://yts.re/browse-movie/0/720p/All/0/latest"},
  "feedly":{spec:"https://feedly.com/index.html#my"},
  "localtrans":{spec:"http://192.168.0.102:12345"},
  "localplex":{spec:"http://192.168.0.102:32400/web"},
  "espnf":{spec:"http://games.espn.go.com/ffl/leagueoffice?leagueId=570639&seasonId=2014"},
  "cbsf":{spec:"http://2002scfl.football.cbssports.com/"},
  "cblog":{spec:"http://blog.coderscabal.org/"},
  "myreddit":{spec:"http://www.reddit.com/user/jmaelstrom/"}
}
 
makeWebJumps([baseWebJumps]);

You’ll notice the function actually takes an array of dictionaries. The reason being is that I like to keep my web jumps organized by category – because I’m kinda weird like that. Also notice the dictionary values are actually objects. spec is mandatory while alt is used if the webjump isn’t supplied an argument.

Pretty slick, eh? Well, not overly – but I find it useful anyway!