Skip to content

Instantly share code, notes, and snippets.

@xbourn
Created March 10, 2009 02:34
Show Gist options
  • Save xbourn/76681 to your computer and use it in GitHub Desktop.
Save xbourn/76681 to your computer and use it in GitHub Desktop.
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"
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment