[Vimperator] A view-source plugin
Andrea Rossato
mailing_list at istitutocolli.org
Fri Feb 29 01:31:44 PST 2008
Hi,
since sometimes I need to open an URL with view-source (for looking
source code served with unrecognized MINE types, for instance), I
wrote this trivial plugin to add 2 commands (and relative key
bindings):
- tviewsource (or 'v') to open the source of an URL in a new tab;
- viewsource (or 'V') to open the current URL's source in a new tab.
I've read that the API is changing, but since I need these functions I
think I'll send a follow up when/if things are going to be broken.
Vimperator is really addictive. Thank you very much!
Cheers,
Andrea Rossato
(an emacs believer ;)
-------------- next part --------------
// Vimperator plugin: 'viewsource'
// Last Change: 02/29/2008
// License: Public Domain
// Version: 0.1
// Author: Andrea Rossato <andrea.rossato at unibz.it>
// INSTALL: put this file into ~/.vimperator/plugin/ (create folders if necessary)
// and restart firefox or :source that file
vimperator.commands.add(new vimperator.Command(["tviewsource", "tv[iewsource]"],
function (args, special)
{
var where = special ? vimperator.NEW_TAB : vimperator.NEW_BACKGROUND_TAB;
if (/\btabopen\b/.test(vimperator.options["activate"]))
where = special ? vimperator.NEW_BACKGROUND_TAB : vimperator.NEW_TAB;
if (args)
vimperator.open("view-source:" + args, where);
else
vimperator.open("about:blank", where);
},
{
usage: ["tviewsource [url]"],
shortHelp: "View the source of an URL in a new tab",
help: "Like <code class=\"command\">:topen</code> but open the source of URLs in a new tab.<br/>",
completer: function (filter) { return vimperator.completion.url(filter); }
}
));
vimperator.mappings.add(new vimperator.Map(vimperator.modes.NORMAL, ["v"],
function ()
{
vimperator.commandline.open(":", "tviewsource ", vimperator.modes.EX);
},
{
shortHelp: "Open the source of a URL in a new tab",
help: "Like <code class=\"mapping\">o</code> but open URLs in a new tab.<br/>"
}
));
vimperator.commands.add(new vimperator.Command(["viewsource", "v[iewsource]"],
function (args, special)
{
if (args)
{
vimperator.open("view-source:" + args);
}
else
{
if (special)
BrowserReloadSkipCache();
else
BrowserReload();
}
},
{
usage: ["viewsource", "v[iewsource]"],
shortHelp: "View the source of the current location",
help: "View the source of the current location.<br/>",
completer: function (filter) { return vimperator.completion.url(filter); }
}
));
vimperator.mappings.add(new vimperator.Map(vimperator.modes.NORMAL, ["V"],
function ()
{
vimperator.open("view-source:" + vimperator.buffer.URL, vimperator.NEW_TAB);
},
{
shortHelp: "View source of the current tab",
help: "Like <code class=\"mapping\">o</code> but open the source of a URL in a new tab.<br/>"
}
));
More information about the Vimperator
mailing list