-
-
Save junk4hos/166737 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* 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: "[email protected]"}, | |
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