Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
A Ubiquity 0.5+ command for Let Me Google That For You
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* This is the Parser 2 API version of the LetMeGoogleThatForYou *
* Ubiquity script compatible with Ubiquity 0.5+. *
* The Legacy parser version is available at *
* http://gist.github.com/45201 *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
var icon = "http://letmegooglethatforyou.com/favicon.ico";
var tu_desc = "<a href=\"http://www.tinyurl.com\">TinyUrl</a>";
var lmg_desc = "<a href=\"http://lmgtfy.com\">Let Me Google That For You</a>";
var tu_api = "http://tinyurl.com/api-create.php?url=http://letmegooglethatforyou.com/?q="
CmdUtils.CreateCommand({
names: ["lmgtfy", "letmegooglethatforyou"],
arguments: [ {role: 'object', nountype: noun_arb_text, label: _('words to let me google for you')} ],
icon: icon,
description: _("Replaces the selected words with a ${tu} of the ${lmg} link", {tu:tu_desc, lmg:lmg_desc}),
preview: function( pblock, args ){
pblock.innerHTML = _("Replaces the selected URL with a tiny LMGTFY url.");
var baseUrl = tu_api;
pblock.innerHTML = _("Replaces the selected URL with ");
jQuery.get( baseUrl + urlencode(args.object.text), function( tinyUrl ) {
if(tinyUrl != "Error") pblock.innerHTML += tinyUrl;
});
},
execute: function( args ) {
//escaping urlToShorten will not create the right tinyurl
var baseUrl = tu_api;
jQuery.get( baseUrl + urlencode(args.object.text), function( tinyUrl ) {
CmdUtils.setSelection( tinyUrl );
});
}
});
CmdUtils.CreateCommand({
name: ["lmgtfy-lucky", "letmegooglethatforyou-lucky"],
arguments: [ {role: 'object', nountype: noun_arb_text, label: _('words to let me google luckily for you')} ],
icon: icon,
description: _("Replaces the selected words with a ${tu} of the ${lmg} link",
{tu:tu_desc,
lmg:"<a href=\"http://lmgtfy.com/\">Let Me Google That For You</a> <i>"+_("I'm Feeling Lucky")+"</i>"}),
preview: function( pblock, args ){
pblock.innerHTML = _("Replaces the selected URL with a tiny, lucky LMGTFY url.");
var baseUrl = tu_api + "&l=1";
pblock.innerHTML = _("Replaces the selected URL with ");
jQuery.get( baseUrl + urlencode(args.object.text), function( tinyUrl ) {
if(tinyUrl != "Error") pblock.innerHTML += tinyUrl;
});
},
execute: function( args ) {
//escaping urlToShorten will not create the right tinyurl
var baseUrl = tu_api + "&l=1";
jQuery.get( baseUrl + urlencode(args.object.text), function( tinyUrl ) {
CmdUtils.setSelection( tinyUrl );
});
}
});
function urlencode(str) {
str = escape(str);
str = str.replace('+', '%2B');
str = str.replace('%20', '+');
str = str.replace('*', '%2A');
str = str.replace('/', '%2F');
str = str.replace('@', '%40');
return str;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.