Created
March 10, 2009 05:02
-
-
Save xbourn/76747 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CmdUtils.CreateCommand({ | |
name: "en2zh", | |
icon: "http://www.google.com/favicon.ico", | |
description: "将当前英文网页翻译为中文", | |
execute: function() { | |
var word = context.focusedWindow.document.location; | |
Utils.openUrlInBrowser( "http://72.14.235.104/translate_c?sl=en&tl=zh-CN&hl=zh-CN&ie=UTF-8&u=" + | |
escape(word) ); | |
}, | |
preview : function(obj){ | |
obj.innerHTML = "将当前英文网页翻译为中文"; | |
} | |
}); | |
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" | |
}); | |
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({ | |
description: "搜索当前网站", | |
name: "gss", | |
takes: {"keywords": noun_arb_text}, | |
preview: "Search keyword(s) from current site", | |
execute: function(keywords) { | |
var rootOfSite = context.focusedWindow.document.location.hostname; | |
var searchTerm= keywords.text; | |
var url = "http://www.google.com/search?q="+searchTerm+ "+site:"+rootOfSite; | |
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: "scholar", | |
url: "http://www.google.com/scholar?q={QUERY}", | |
icon: "http://www.google.com/favicon.ico", | |
description: "Searches Google Scholar for a paper." | |
}); | |
makeSearchCommand({ | |
name: "btchina", | |
url: "http://search3.btchina.net/btsearch.php?query={QUERY}&type=0", | |
icon: "http://static.mininova.org/images/favicon.ico", | |
description: "Search btchina for a torrent." | |
}); | |
makeSearchCommand({ | |
name: "xunlei", | |
url: "http://www.gougou.com/search?search={QUERY}&sortby=6", | |
icon: "http://img.gougou.com/comm/gougou.ico", | |
description: "Searches Xunlei for something" | |
}); | |
makeSearchCommand({ | |
name: "douban", | |
url: "http://www.douban.com/subject_search?ie=utf-8&search_text={QUERY}", | |
icon: "http://lotho.douban.com/favicon.ico", | |
description: "Searches douban for your title", | |
author: { name: "LI Gang", email: "superligang at gmail.com"}, | |
preview: function( pblock, directObject) { | |
var query = directObject.text; | |
var urlobject = "http://www.douban.com/subject_search?search_text={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=800 height=600/></td></tr></TABLE>"; | |
pblock.innerHTML = msg; | |
} | |
} | |
}); | |
makeSearchCommand({ | |
name: "verycd", | |
url: "http://www.verycd.com/search/folders/{QUERY}", | |
icon: "http://www.verycd.com/favicon.ico", | |
description: "Searches verycd for your title", | |
}); | |
CmdUtils.CreateCommand({ | |
name: "news", | |
takes: { | |
"news title": noun_arb_text | |
}, | |
preview: function(pblock, title) { | |
pblock.innerHTML = "Will search for news titles containing: " + title.text; | |
}, | |
execute: function(directObject) { | |
var url = "http://news.google.com/news?q={QUERY}"; | |
var query = directObject.text; | |
var urlString = url.replace("{QUERY}", query); | |
Utils.openUrlInBrowser(urlString); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment