Created
January 9, 2009 18:03
-
-
Save bollwyvl/45201 to your computer and use it in GitHub Desktop.
A Ubiquity command for Let Me Google That For You
This file contains 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 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