Skip to content

Instantly share code, notes, and snippets.

@junk4hos
Created August 12, 2009 20:31
Show Gist options
  • Save junk4hos/166737 to your computer and use it in GitHub Desktop.
Save junk4hos/166737 to your computer and use it in GitHub Desktop.
/* This is a template command. */
CmdUtils.CreateCommand({
names: ["new tab","new-tab"],
icon: "http://www.mozilla.com/favicon.ico",
description: "Opens the passed URL in a new tab",
help: "open-in-new-tab http://www.mozilla.com",
author: {name: "Scott Hosfeld", email: "junk4hos+ubiquity@gmail.com"},
license: "GPL",
homepage: "",
arguments: [{role: 'object', nountype: noun_arb_text, label:"url"}],
_getUrl: function(args){
var url = args.object.text;
url = url.replace(/\s+/g, "");
var proto = /^(http|https|ftp)\:///
if (!proto.test(url)){url='http://'+url;}
var urlRegx = /^((http|https|ftp)\:\/\/).*(\.[\w]{2,6})((\.[\w]{2,6})|(\/[a-zA-Z0-9\-]*)*)$/
var retUrl = {};
retUrl.url = url;
retUrl.goodUrl = urlRegx.test(url);
return retUrl;
},
preview: function preview(pblock, args) {
var urlObj = this._getUrl(args);
if (urlObj.goodUrl){
pblock.innerHTML = _("Open <b>${url}</b> in a new tab",urlObj);
}else{
pblock.innerHTML = _("${url} is not a valid URL", urlObj);
}
},
execute: function(args) {
var urlObj = this._getUrl(args);
if (urlObj.goodUrl){
Utils.openUrlInBrowser(urlObj.url);
}else{
displayMessage(_("${url} is not a valid URL", urlObj ));
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment