Forgot to attach file.. here it is.

-- 
John Foerch
/**
 * (C) Copyright 2012 John J. Foerch
 *
 * Use, modification, and distribution are subject to the terms specified in the
 * COPYING file.
**/

var redirects = {};

function define_client_redirect (name, from, to) {
    redirects[name] = { from: from, to: to };
}

function do_client_redirect (buffer, request, location) {
    try {
        location = location.QueryInterface(Ci.nsIURL);
        for (let [name, def] in Iterator(redirects)) {
            if (def.from instanceof RegExp)
                var m = def.from.exec(location.spec);
            else
                m = def.from(location);
            if (m) {
                buffer.window.minibuffer.message("Executing client redirect: 
"+name);
                if (typeof m == "string")
                    var to = m;
                else
                    to = def.to(m);
                var history = buffer.web_navigation.sessionHistory;
                if (history.index > 0)
                    history.getEntryAtIndex(history.index - 1, true)
                else
                    history.PurgeHistory(1);
                buffer.load(to);
                return;
            }
        }
    } catch (e) {}
}
add_hook('content_buffer_location_change_hook', do_client_redirect);

conkeror.define_client_redirect = define_client_redirect;

provide("client-redirect");
_______________________________________________
Conkeror mailing list
[email protected]
https://www.mozdev.org/mailman/listinfo/conkeror

Reply via email to