douban_search_num_html = "<div><b>${num}</b> douban items found matching <b>${term}</b>.</div><br/>";
douban_search_item_html = "<div style=\"clear: both;\"><b><u><a href=\"${item.link[1][\"@href\"]}\">${item.title[\"$t\"]}</a></u></b><br/>" +
"<img src=\"${item.link[2][\"@href\"]}\" style=\"float: left; height: 80px; background-color: white;\" />" +
"{for aut in item.author}<small>${aut.name[\"$t\"]}.</small>{/for}" +
"{for db in item[\"db:attribute\"]}<small>${db[\"$t\"]}.</small>{/for}" +
"</div><br/>";
douban_search_item_no_img_html = "<div style=\"clear: both;\"><b><u><a href=\"${item.link[1][\"@href\"]}\">${item.title[\"$t\"]}</a></u></b><br/>" +
"{for aut in item.author}<small>${aut.name[\"$t\"]}.</small>{/for}" +
"{for db in item[\"db:attribute\"]}<small>${db[\"$t\"]}.</small>{/for}" +
"</div><br/>";
noun_type_section = new CmdUtils.NounType( "section",
[ "generic" , "music", "movie", "book" ]
);
douban_section_url_template = {
"generic" : "http://www.douban.com/subject_search?search_text=${term}",
"music" : "http://www.douban.com/subject_search?search_text=${term}&cat=1003",
"movie" : "http://www.douban.com/subject_search?search_text=${term}&cat=1002",
"book" : "http://www.douban.com/subject_search?search_text=${term}&cat=1001",
};
CmdUtils.CreateCommand({
name: "douban-search",
takes: {term: noun_arb_text},
modifiers: { in: noun_type_section },
icon: "http://www.douban.com/pics/dou24.gif",
homepage: "http://gist.github.com/31480",
author: { name: "CHEN Daizhuo", email: "chendaizhuo@gmail.com" },
license: "GPL",
description: "douban-search: douban becomes ubiquity.",
help: "Invokes the douban search engine from your ubiquity command line.",
__getSection : function( rawData ) {
return rawData.in.text || "generic";
},
__getSearchTerm : function( rawData ) {
return rawData.text || "";
},
__getTargetURL : function( section, term ) {
if (term.length < 1) {
if (section == "generic") section="";
return "http://www.douban.com/" + section;
}
var template = douban_section_url_template[section];
var subs = {"term" : term };
var res = CmdUtils.renderTemplate(template, subs);
return res;
},
preview: function( pblock, expSearchTerm, modifiers ) {
var section = this.__getSection(modifiers);
var term = this.__getSearchTerm(expSearchTerm);
var msg = (term.length < 1)
? ("Go to the <b>" + section +"</b> home page of douban")
: ("Searches douban (" + section + ") for " + term);
pblock.innerHTML = msg;
if (section != "generic") {
var url = "http://api.douban.com/" + section + "/subjects";
var params = {
q: term,
"start-index": 1,
"max-results": 3,
alt: "json",
apikey: "05eaefdd447763e211c0cf97cd662ba6",
};
CmdUtils.previewGet( pblock, url, params, function(data) {
pblock.innerHTML = CmdUtils.renderTemplate(
douban_search_num_html,
{ term: term, num: data["opensearch:totalResults"]["$t"] }
);
for (var i=0;i<data.entry.length;i++) {
if (data.entry[i].link.length>2) {
pblock.innerHTML = pblock.innerHTML + CmdUtils.renderTemplate(
douban_search_item_html,
{item: data.entry[i] }
); }
else {
pblock.innerHTML = pblock.innerHTML + CmdUtils.renderTemplate(
douban_search_item_no_img_html,
{item: data.entry[i] }
); } }
}, "json");
}
},
execute: function( expSearchTerm, modifiers ) {
var section = this.__getSection(modifiers);
var term = this.__getSearchTerm(expSearchTerm);
var url = this.__getTargetURL(section, term);
Utils.openUrlInBrowser(url);
}
})
makeSearchCommand({
name: "scholar",
url: "http://www.google.com/scholar?q={QUERY}",
icon: "http://www.google.com/favicon.ico",
description: "Searches Google Scholar for a paper."
});
CmdUtils.CreateCommand({
name: "chinese",
description: "Translates from one language to Chinese.",
icon: "http://www.google.com/favicon.ico",
takes: {"text to translate": noun_arb_text},
modifiers: {to: noun_type_language, from: noun_type_language},
execute: function( directObj, languages ) {
var toLang = "Chinese";
var fromLang = languages.from.text || "";
var toLangCode = Languages[toLang.toUpperCase()];
var fromLangCode = Languages[fromLang.toUpperCase()];
//translateTo( directObj.text, {to:toLangCode} );
if (fromLang.length > 0){
translateTo( directObj.text, {from:fromLangCode, to:toLangCode} );
} else {
var dictURL = "http://dict.cn/" + directObj.text;
Utils.openUrlInBrowser(dictURL);
CmdUtils.setLastResult(dictURL);
};
},
preview: function( pblock, directObj, languages ) {
var toLang = languages.to.text || "Chinese";
var textToTranslate = directObj.text;
var toLangCode = Languages[toLang.toUpperCase()];
var lang = toLang[0].toUpperCase() + toLang.substr(1);
pblock.innerHTML = "Replaces the selected text with the " + lang + " translation:<br/>";
translateTo( textToTranslate, {to:toLangCode}, function( translation ) {
pblock.innerHTML = "Replaces the selected text with the " +lang + " translation:<br/>";
pblock.innerHTML += "<i style=’padding:10px;color: #CCC;display:block;’>" + translation + "</i>";
});
}
});
CmdUtils.CreateCommand({
name: "english",
takes: {search: noun_arb_text},
author: { name: "LI Gang", email: "superligang at gmail.com"},
description: "look up the word for the english explanation",
preview: function( pblock, directObject) {
var query = directObject.text;
var urlobject = "http://www.objectgraph.com/dictionary/dict.aspx?k={QUERY}";
if (query.length > 0) {
var urlString = urlobject.replace("{QUERY}", query);
var running = "searching for " + query;
var msg = running + "<TABLE bgcolor=WHITE><tr><td><iframe background-color=WHITE src=’" + urlString + "’ width=480 height=480/></td></tr></TABLE>";
pblock.innerHTML = msg;
}
},
execute: function(directObject) {
var urldict = "http://www.dictionary.hm/search_function.php?q={QUERY}";
var query = directObject.text;
if (query.length > 0) {
var urlString = urldict.replace("{QUERY}", query);
Utils.openUrlInBrowser(urlString);
}
}
});
CmdUtils.CreateCommand({
name: "shooter",
icon: "http://www.shooter.cn/favicon.ico",
homepage: "http://shooter.cn/",
author: { name: "toopoo@CCF&DRL", email: "toopooliu@gmail.com"},
license: "GPL",
description: "Shooter search",
help: "sh movie",
takes: {"movie": noun_arb_text},
preview: function( pblock, movie ) {
var msg = "搜索电影" + movie.text + "的字幕";
pblock.innerHTML = msg;
},
execute: function(movie) {
var url="http://www.shooter.cn/search/Sub:"
Utils.openUrlInBrowser( url + movie.text + "/?x=0&y=0&");
}
});
CmdUtils.CreateCommand({
name: "hdbits",
icon: "http://hdbits.org/favicon.ico",
homepage: "http://hdbits.org/",
description: "hdbits search",
takes: {"movie": noun_arb_text},
execute: function(movie) {
var url="http://hdbits.org/browse.php?incldead=0&from=&to=&imdbgt=0&imdblt=10&uppedby=&imdb=&search="
Utils.openUrlInBrowser( url + movie.text );
}
});
CmdUtils.CreateCommand({
name: "naver",
icon: "http://www.naver.com/favicon.ico",
homepage: "http://www.naver.com/",
author: { name: "jimey@jimey.cn", email: "jimeyren@gmail.com"},
license: "GPL",
description: "Naver dic search",
takes: {"word": noun_arb_text},
execute: function(word) {
var wordsnaver = word.text
var urlnavers ="http://cndic.naver.com/search.nhn?query_euckr=&query_utf=&dic_where=cndic&kind=&query={QUERY}&x=0&y=0";
if (wordsnaver.length > 0) {
var urlnaver = urlnavers.replace("{QUERY}", wordsnaver);
Utils.openUrlInBrowser(urlnaver);
}
}
});
CmdUtils.CreateCommand({
name: "drl",
description: "打开Dream Land 论坛的首页",
help: "打开Dream Land 论坛的首页",
preview: function( pblock ) {
var msg = "打开Dream Land 论坛的首页";
pblock.innerHTML = msg;
},
execute: function() {
var url = "https://dream4ever.org";
Utils.openUrlInBrowser( url);
}
})
CmdUtils.CreateCommand({
name: "nice",
icon: "http://www.nicetranslator.com/favicon.ico",
description: "打开翻译",
preview: function( pblock ) {
var msg = "打开翻译";
pblock.innerHTML = msg;
},
execute: function() {
var url = "http://www.nicetranslator.com/";
Utils.openUrlInBrowser( url);
}
})
CmdUtils.CreateCommand({
name: "reader",
icon: "http://www.google.com/reader/ui/favicon.ico",
description: "打开google阅读器",
preview: function( pblock ) {
var msg = "打开google阅读器";
pblock.innerHTML = msg;
},
execute: function() {
var url = "http://www.google.com/reader/";
Utils.openUrlInBrowser( url);
}
})
makeSearchCommand({
name: "Baidu",
url: "http://www.baidu.com/s?wd={QUERY}",
icon: "http://www.baidu.com/favicon.ico",
homepage: "http://blog.eshangrao.com/",
author: { name: "feiy", email: "eshangrao@gmail.com"},
contributors: ["feiy"],
license: "MPL",
description: "Searches Baidu for your words.",
preview: function(pblock, directObject) {
var searchTerm = directObject.text;
var pTemplate = "Searches Baidu for <b>${query}</b>";
var pData = {query: searchTerm};
pblock.innerHTML = CmdUtils.renderTemplate(pTemplate, pData);
var url = "http://www.baidu.com/s";
var params = { wd: searchTerm };
jQuery.ajax({
type: "get",
url: url,
data: params,
charset1: "gb2312",
dataType: "html",
error: function() {
displayMessage("Searchs Baidu Error");
},
success: function(data) {
var numToDisplay = 3;
var f_cache_p=data.indexOf("cache.baidu.com");
var f_table_p=data.substring(0,f_cache_p).lastIndexOf("<table");
var l_cache_p=data.lastIndexOf("cache.baidu.com");
var l_table_p=data.substr(l_cache_p).indexOf("</table>");
var result_html=data.substring(f_table_p,l_cache_p+l_table_p+"</table>".length);
var tables=result_html.split("</table>",numToDisplay);
var filter_html=tables.join("</table>");
//var decoder=Components.classes["@mozilla.org/intl/utf8converterservice;1"].getService(Components.interfaces.nsIUTF8ConverterService);
//pblock.innerHTML = decoder.convertStringToUTF8(filter_html,"GB2312",false);
pblock.innerHTML = filter_html
}
});
}
});
makeSearchCommand({
name: "Flex ",
url: "http://community.adobe.com/help/search.html?q={QUERY}&lbl=flex_product_adobelr&x=0&y=0",
homepage: "http://blog.eshangrao.com/",
author: { name: "feiy", email: "eshangrao@gmail.com"},
contributors: ["feiy"],
license: "MPL",
description: "Flex Community Help Searches for your words."
});
makeSearchCommand({
name: "Dict",
url: "http://dict.cn/search.php?q={QUERY}",
icon: "http://www.dict.cn/favicon.ico",
homepage: "http://blog.eshangrao.com/",
author: { name: "feiy", email: "eshangrao@gmail.com"},
contributors: ["feiy"],
license: "MPL",
description: "Dict.CN Dictionary"
});
makeSearchCommand({
name: "last",
url: "http://cn.last.fm/search?m=all&q={QUERY}",
icon: "http://cn.last.fm//favicon.ico",
license: "MPL",
description: "Last.fm"
});

标签:, ,

相关日志


相关博文

评论

Good.Be the first to comment on this entry.

Post comment

comment has COPYRIGHT too!