XML.ignoreWhitespace = XML.prettyPrinting = false;
const Name = 'eijiro', EOW = 'http://eow.alc.co.jp/',
Base = '<style>'+ <![CDATA[
body {line-height:1.3}
ul, ol {padding-left:1.2em}
ul, ol, li {margin:0 0 0.2em}
font {color:inherit}
a img {border:none}
button {padding:0; border-width:1px; text-transform:uppercase}
button[disabled] {background-color:transparent; color:inherit}
button, td.active {font:bold 92% monospace}
td.active a {margin:0 0.3em}
.q {position:absolute; font:bold 128% sans-serif; top:0; left:0.3em}
.navi {text-align:right; margin-bottom:1ex}
.pageNavi {
border-collapse:collapse; float:none; display:inline-block;
vertical-align:middle; margin-right:1em}
.searchwordfont {color:inherit; font-weight:bolder}
.exp {display:none}
.logo {display:inline-block}
.logo > img {vertical-align:bottom}
.error {font-style:oblique; line-height:1.8}
.loading {opacity:0.9}
.loading + .logo {opacity:0.4}
.error + .logo {opacity:0.7}
#resultList button, .sas button {margin-right:0.2em}
#resultList > div:first-child {display:none}
]]> +'</style>'+
<div class={Name}><div id={Name}> </div
><a class="logo" href={EOW} accesskey="/"
><img src="http://eowimg.alc.co.jp/content/img/logo_eow.gif"/></a></div>,
A2BMap = {'\u524D\u3078': [',', '<,'], '\u6B21\u3078': ['.', '.>']};
function a2b(a, txt){
var pg = /\d+/(a.href), [key, lbl] = A2BMap[txt] || [txt.slice(-1), txt];
return <button accesskey={key} value={pg}>{lbl}</button>.toXMLString();
}
function ng(c){
c.textContent = Array.slice(arguments, 1).join(' ');
c.className = 'error';
}
function request(x, i)(
x ? EOW + encodeURIComponent(x) +'/UTF-8/'+ (i > 1 ? '?pg='+ i : '') : EOW);
function result(cn, htm, go){
if(!/<div id="resultArea"[^]+?<\/ul>\s*(?=<script)/.test(htm))
return ng(cn, '??');
var $t = $(RegExp.lastMatch), q = $t.find('#searchWord').text();
var [pn] = $t.find('.pageNavi').find('td').each(function ej_navix(){
var [a] = this.getElementsByTagName('a'), t = this.textContent.trim();
this.innerHTML =
a ? a2b(a, t)
: <a href={request(q, t)} accesskey={t[0]}><b>{t}</b></a>;
}).end();
var [rl] = $t.find('#resultList').find('.refvocab').each(linx).end();
($('<div class="navi"><div class="q">'+ q +'</div></div>')
.append(pn, $t.find('#itemsNumber').contents())
.add($t.find('.sas').find('a[href^="javascript:"]').each(idiomx).end())
.add(rl)
.appendTo((cn.innerHTML = cn.className = '', cn)));
pn.addEventListener('focus', function ej_onfocus({target: b}){
if(b.nodeName.toLowerCase() !== 'button') return;
b.blur();
b.disabled = true;
go(b.value);
}, true);
if(rl) rl.ondblclick = wclix;
}
function idiomx(){
with(this) if(~href.indexOf('changeIdiom')){
parentNode.removeChild(previousSibling);
parentNode.removeChild(this);
} else href = request(''+ /".*?"/(href));
}
function linx(){
var txt = this.textContent;
this.innerHTML = txt.link(request(txt));
}
function wclix(e){
var s = e.view.getSelection() +'';
if(!s) return;
var U = context.chromeWindow.gUbiquity;
U.__textBox.value = Name +' '+ s;
U.__processInput();
}
CmdUtils.CreateCommand({
names: [Name, 'eow'],
icon: EOW +'favicon.ico',
description: (
'\u82F1\u8F9E\u90DE on the WEB'.link(EOW) +' + '+
'Incremental Search'.link(
'http://eowimg.alc.co.jp/content/help/tips/tip013.html')),
help: 'Double-clicking words may work.',
argument: {
name: 'eow Incremental Search',
label: '?',
rankLast: true,
suggest: function nt_eow_suggest(txt, htm, cb, sx){
var ss = [CmdUtils.makeSugg(txt, htm, null, .4, sx)];
sx || ss.push($.ajax({
url: 'http://eow.alc.co.jp/eow/sg/?q='+ encodeURIComponent(txt),
dataType: 'xml',
success: function nt_eow_success(xml){
var words = xml.getElementsByTagName('word');
if(1 in words) cb([
CmdUtils.makeSugg(decodeURIComponent(w.textContent),
null, null, .3)
for each(w in Array.slice(words, 1))]);
}}));
return ss;
},
},
execute: function ej_execute(args){
Utils.openUrlInBrowser(request(args.object.text));
},
preview: function ej_preview(pb, args, page){
var cn, q = Utils.trim(args.object.text), doc = pb.ownerDocument;
while(!(cn = doc.getElementById(Name))) pb.innerHTML = Base;
if(!q) return;
cn.className += ' loading';
CmdUtils.previewAjax(pb, {
url: request(q, page),
success: function ej_success(htm){
result(cn, htm, function go(pg){ ej_preview(pb, args, pg) });
doc.defaultView.scrollTo(0, 0);
var sa = ' a[href^="http://eow.alc.co.jp/"]';
var sb = '#resultList'+ sa +', .sas'+ sa, i = 0, xopt = this;
for each(let a in Array.slice(cn.querySelectorAll(sb))){
var b = doc.createElement('button');
b.textContent = b.accessKey = (++i + 9).toString(36);
b.addEventListener('focus', ej_inline, false);
a.parentNode.insertBefore(b, a);
}
function ej_inline(){
this.blur();
this.disabled = true;
cn.className += ' loading';
xopt.url = this.nextSibling.href;
CmdUtils.previewAjax(pb, xopt);
}
},
error: function ej_error(x, s){
ng(cn, x.status, x.statusText, ' (', s, ')');
},
});
},
author: 'satyr', license: 'MIT',
});