Skip to content

Instantly share code, notes, and snippets.

Created March 20, 2010 08:48
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 anonymous/338560 to your computer and use it in GitHub Desktop.
Save anonymous/338560 to your computer and use it in GitHub Desktop.
var data=null;
jetpack.future.import("selection");
jetpack.selection.onSelection(
function(){
data = 'http://tw.dictionary.yahoo.com/search?ei=UTF-8&p='+jetpack.selection.text;
$.ajax({
url: data,
dataType: 'html',
success: function(response) {
var matches = response.match(/<div class\=pexplain>([^>]+)<\/div>/g);
if (!matches) { jetpack.notifications.show('no matches!'); return; }
var result = ''
for (var i = 0; i < matches.length; i++) {
result += (matches[i].replace(/<div class\=pexplain>/, '').replace(/<\/div>/,'')) + "\n";
}
jetpack.notifications.show(result);
},
error: function(xhr,stat,err) { console.log(stat); } }
);
}
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment