Skip to content

Instantly share code, notes, and snippets.

@Yasushi
Created September 19, 2008 04:48
Show Gist options
  • Save Yasushi/11541 to your computer and use it in GitHub Desktop.
Save Yasushi/11541 to your computer and use it in GitHub Desktop.
undefined
CmdUtils.CreateCommand({
name: "goodic",
icon: "http://dictionary.goo.ne.jp/favicon.ico",
homepage: "http://dictionary.goo.ne.jp/",
description: "Searches <a href=\"http://dictionary.goo.ne.jp/\">goo 辞書</a> for your words.",
takes: {"search term": noun_arb_text},
_url: function(word) {
if(word.length == 0) {
return;
}
const UConv = Components.classes['@mozilla.org/intl/scriptableunicodeconverter']
.getService(Components.interfaces.nsIScriptableUnicodeConverter);
UConv.charset='UTF-8';
return "http://dictionary.goo.ne.jp/srch/all/" + escape(UConv.ConvertFromUnicode(word)) + '/m0u/';
},
preview: function( pblock, input ) {
pblock.innerHTML = "Performs a goo dictionary search";
var url = this._url(input.text);
if(!url) {return;}
jQuery.ajax({
type: "GET",
url: url,
success: function(data) {
var doc=jQuery(data);
var dicco=doc.find("h2.ch04").length;
pblock.innerHTML="";
const template = "<p><b>${name}(${count}件)</b>: ${result}</p>";
for(var i = 0; i < dicco; i++) {
var h = doc.find("h2.ch04:eq("+i+")");
pblock.innerHTML+="<p>"+h.text()+"</p>";
var r = h.next("div.allResultList");
r.find("a").each(function(i){
if(this.href.match("^chrome://ubiquity/")) {
this.href=this.href.replace("chrome://ubiquity","http://dictionary.goo.ne.jp");
}
});
pblock.innerHTML+=r.html();
}
}
});
},
execute: function(input) {
var url = this._url(input.text);
if (url) {
Utils.openUrlInBrowser(url);
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment