welcome: please sign in
location: ClientRedirect

The module client-redirect provides a mechanism by which Conkeror can automatically preform a defined redirection on configured urls and url patterns. When a matching url is encountered as the location of a buffer, a client-redirect translates it into another url to load instead. This mechanism can be used to "skip" intermediary webpages when browsing, and go straight to the content you want.

1. Enabling Client Redirects


2. define_client_redirect

Client redirects are created by calling define_client_redirect. This procedure takes as its arguments a name for the redirect and any number of transforms. The transforms are composed together into a procedure that either matches an url and returns a new url to load instead, or it returns null, meaning no match, and no redirection.

define_client_redirect(name, transform...);
The name is just a string naming the redirect. Client redirects are defined in their own namespace, separate from functions, variables, commands, etcetera.

Each transform may be a function or a RegExp. If the first transform is a function, it will be called with an nsIURI object; if it is a RegExp, it will be matched against the string spec of the uri. If any transform returns null (or false) the entire chain of transforms returns null, meaning no match, and no redirect. The end result of the chain of transforms must be a string url, but intermediate results between one transform and the next can be anything at all. The result of a RegExp match is a regexp result object, so a transform function following a RegExp should take this type of object as its argument.

3. Examples

3.1. Google Images

This is an example of a client redirect that uses a single function for the transform. It skips the intermediary "imgres" page at Google Images.

    function (uri) {
        return /(images|www)\.google\.com$/.test(uri.host)
            && uri.filePath == "/imgres"
            && regexp_exec(/imgurl=([^&]+)/, uri.query, 1);

3.2. Imgur

This is an example of a client redirect that uses two transforms. The first is a regular expression that matches urls at imgur.com, and the second is a function that transforms the match result into the url of the jpeg image.

    build_url_regexp($domain = "imgur", $path = /.*/),
    function (m) {
        return m[0].replace("//", "//i.")+".jpg";

Conkeror.org: ClientRedirect (last edited 2012-02-17 23:50:41 by retroj)