Skip to content

Instantly share code, notes, and snippets.

@satyr
Created September 15, 2008 19:53
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 satyr/10926 to your computer and use it in GitHub Desktop.
Save satyr/10926 to your computer and use it in GitHub Desktop.
const Dicg = 'http://ext.dictionary.goo.ne.jp/',
Goo = 'http://goo.ne.jp/',
ID = '#_'+ (Math.random() +'').slice(2),
Base = <div class="dicg"><base href={Dicg}/><style><![CDATA[
@ul {padding-left:16px; margin:0 0 6px}
@h2, @h3 {font-size:96%; margin:0 0 4px}
@img, @.logo {background-color:#fff; border:none}
@li img {margin:0}
@li a + img {margin-left:2px}
@.logo {padding:4px 0; text-align:center; width:148px; height:40px}
@.loading + .logo {opacity:0.4}
@.error + .logo {opacity:0.7}
]]></style><div id={ID.slice(1)}/><div class="logo"><a href={Goo}
><img src="http://cmm001.goo.ne.jp/img/logo/goo.gif"/></a><a href={Dicg}
><img src="http://cmm001.goo.ne.jp/img/sn/sn_31.gif"/></a></div></div
>.toXMLString().replace(/@/g, '.dicg ');
var pq;
CmdUtils.CreateCommand({
name: "dicg",
icon: Goo +'favicon.ico',
takes: {'?': noun_arb_text},
description: ''+<>Consults <a href={Dicg}>goo &#x8f9e;&#x66f8;</a>.</>,
execute: function({text}){ Utils.openUrlInBrowser(request(text)) },
preview: function(pbl, {text: q}){
var $p = jQuery(pbl), $c = $p.find(ID);
if(!$c[0]) $c = $p.html(Base).find(ID), pq = '';
if(!q || pq === (pq = q)) return;
$c.addClass('loading');
CmdUtils.previewAjax(pbl, {
url: request(q),
success: function(htm){
var m = /<!--\/ch04_1-[\s\S]+? cookie -->/(htm);
if(!m) return oops($c, '??');
$c.removeClass()
.html(m[0].replace(/\b((?:src|href)=\")(?!http:)\/?/g, '$1'+ Dicg)
.replace(/\bonclick=".*?"/ig, ''));
},
error: function(x){ oops($c, x.status, x.statusText) },
});
},
author: 'satyr'.link('http://d.hatena.ne.jp/murky-satyr'), license: 'MIT',
});
function oops($c){
$c.removeClass('loading').addClass('error')
.text(Array.slice(arguments, 1).join(' '));
}
function request(q)
Dicg +'srch/all/'+ encodeURIComponent(q) +'/m0u/';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment