Skip to content

Instantly share code, notes, and snippets.

@zpao
Created May 1, 2009 00:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zpao/104784 to your computer and use it in GitHub Desktop.
Save zpao/104784 to your computer and use it in GitHub Desktop.
CmdUtils.CreateCommand({
name: "tr.im",
preview: "Trims URLs using the tr.im service",
homepage: "http://tr.im/",
help: "Trims the selected URL.",
takes: {"url": noun_arb_text},
modifiers: {name: noun_arb_text, password: noun_arb_text},
execute: function(urlToTrim, mods) {
var url = "http://tr.im/api/trim_url.json";
var params = Array();
params.url = urlToTrim.text;
if (!params.url)
params.url = CmdUtils.getDocument().location.href;
var TrImPrefs = Application.storage.get ("extension.trim.TrImPrefs", false);
if (mods.name.text && mods.password.text) {
params.username = mods.name.text;
params.password = mods.password.text;
} else if (TrImPrefs) {
params.username = TrImPrefs.getCharPref ('username');
params.password = TrImPrefs.getCharPref ('password');
}
params.api_key = '7Ctm8v3s5Fr4ePaJ8xzsrJSQGwjC68SFkeAHDrydiuEKjccY';
jQuery.get (url, params, function (reply) {
if (reply.status.code >= 400)
displayMessage (reply.status.message);
else {
CmdUtils.copyToClipboard (reply.url);
displayMessage ('Copied the trimmed URL ('+reply.url+') to your clipboard.');
}
}, 'json');
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment