Skip to content

Instantly share code, notes, and snippets.

@mjpieters
Created January 15, 2009 11:25
Show Gist options
  • Save mjpieters/47363 to your computer and use it in GitHub Desktop.
Save mjpieters/47363 to your computer and use it in GitHub Desktop.
Urban Dictionary ubiquity search command
(function($) {
makeSearchCommand({
name: "urban-dictionary",
author: {name: "Martijn Pieters", email: "[email protected]"},
description: "Looks up definition in the Urban Dictionary",
icon: "http://www.urbandictionary.com/favicon.ico",
url:"http://www.urbandictionary.com/define.php?term={QUERY}",
preview: function(pblock, search) {
if (search.text.length < 1) {
$(pblock).html("Definition from the <b>Urban Dictionary</b>");
return;
}
CmdUtils.previewGet(
pblock,
this.url.replace("{QUERY}", escape(search.text)),
function(doc) {
doc = $(doc.replace(/<script(.|\s)*?\/script>/g, ""));
$(pblock).empty();
$(pblock).append(
$('<div/>')
.addClass('definition')
.append(doc.find('td.text:first div.definition')
)
);
$(pblock).append('<br/>');
$(pblock).append(
$('<div/>')
.addClass('example').css('font-style', 'italic')
.append(doc.find('td.text:first div.example'))
);
}
);
},
previewDelay: 10,
});
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment