Skip to content

Instantly share code, notes, and snippets.

@bollwyvl
Created January 9, 2009 18:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save bollwyvl/45201 to your computer and use it in GitHub Desktop.
Save bollwyvl/45201 to your computer and use it in GitHub Desktop.
A Ubiquity command for Let Me Google That For You
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* This is the Legacy version of the LetMeGoogleThatForYou *
* Ubiquity script compatible with Ubiquity <0.5. *
* This version will not be updated. *
* The Parser 2 API version is available at *
* http://gist.github.com/144222 *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
CmdUtils.CreateCommand({
name: "lmgtfy",
synonyms: ["letmegooglethatforyou"],
takes: {"words to google": noun_arb_text},
icon: "http://letmegooglethatforyou.com/favicon.ico",
description: "Replaces the selected words with a <a href=\"http://www.tinyurl.com\">TinyUrl</a> of the <a href=\"\">Let Me Google That For You</a> link",
preview: function( pblock, urlToShorten ){
pblock.innerHTML = "Replaces the selected URL with a tiny LMGTFY url.";
var baseUrl = "http://tinyurl.com/api-create.php?url=http://letmegooglethatforyou.com/?q=";
pblock.innerHTML = "Replaces the selected URL with ",
jQuery.get( baseUrl + urlencode(urlToShorten.text), function( tinyUrl ) {
if(tinyUrl != "Error") pblock.innerHTML += tinyUrl;
});
},
execute: function( urlToShorten ) {
//escaping urlToShorten will not create the right tinyurl
var baseUrl = "http://tinyurl.com/api-create.php?url=http://letmegooglethatforyou.com/?q=";
jQuery.get( baseUrl + urlencode(urlToShorten.text), function( tinyUrl ) {
CmdUtils.setSelection( tinyUrl );
});
}
});
CmdUtils.CreateCommand({
name: "lmgtfy-lucky",
synonyms: ["letmegooglethatforyou-lucky"],
takes: {"words to google": noun_arb_text},
icon: "http://letmegooglethatforyou.com/favicon.ico",
description: "Replaces the selected words with a <a href=\"http://www.tinyurl.com\">TinyUrl</a> of the <a href=\"\">Let Me Google That For You</a> <i>I'm Feeling Lucky</i>link",
preview: function( pblock, urlToShorten ){
pblock.innerHTML = "Replaces the selected URL with a tiny LMGTFY <i>I'm Feeling Lucky</i> url.";
var baseUrl = "http://tinyurl.com/api-create.php?url=http://letmegooglethatforyou.com/?l=1&q=";
pblock.innerHTML = "Replaces the selected URL with ",
jQuery.get( baseUrl + urlencode(urlToShorten.text), function( tinyUrl ) {
if(tinyUrl != "Error") pblock.innerHTML += tinyUrl;
});
},
execute: function( urlToShorten ) {
//escaping urlToShorten will not create the right tinyurl
var baseUrl = "http://tinyurl.com/api-create.php?url=http://letmegooglethatforyou.com/?l=1&q=";
jQuery.get( baseUrl + urlencode(urlToShorten.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