Skip to content

Instantly share code, notes, and snippets.

/gist:338560

Created Mar 20, 2010
Embed
What would you like to do?
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