Skip to content

Instantly share code, notes, and snippets.

@sealence
Created January 20, 2009 10:07
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 sealence/49422 to your computer and use it in GitHub Desktop.
Save sealence/49422 to your computer and use it in GitHub Desktop.
Ubiquity: irecite
/* command "irecite" */
CmdUtils.CreateCommand({
names: ["irecite"],
icon: "http://res.iciba.com/dict/favicon.ico",
homepage: "http://scb.iciba.com/day/",
author: { name: "Sealence", email: "sealence@gmail.com"},
license: "GPL",
description: "Recite word everyday",
arguments: [ {role: 'object', nountype: noun_arb_text, label: 'input'} ],
baseurl: "http://scb.iciba.com/day",
execute:function(args){
var input = args.object.text;
var url = this.baseurl;
if ( input.length > 0 )
url += '_' + input + '.shtml';
Utils.openUrlInBrowser(url);
},
preview: function( pblock, args ) {
var input = args.object.text;
var url = this.baseurl;
if ( input.length > 0 )
url += '_' + input + '.shtml';
Utils.parseRemoteDocument(
url, // URL
null, // post data
function(doc) { // success callback
var max = 5;
var top = null, bottom = null, data = '';
for (var i=0;i<max;i++){
top = jQuery('#top' + i, doc).html();
bottom = jQuery('#bottom' + i + ' div', doc).html();
data += '<b>' + top + '</b>' + bottom + '<p/>';
}
pblock.innerHTML = data ;
},
function() { // error callback
pblock.innerHTML = "Error!";
}
);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment