satyr (owner)

Revisions

gist: 8346 Download_button fork
public
Description:
英辞郞
Public Clone URL: git://gist.github.com/8346.git
Embed All Files: show embed
eijiro.ubiq.js #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
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:0 0 1ex 0; width:99%}
  .pageNavi {
    border-collapse:collapse; float:none; display:inline-block;
    vertical-align:middle; margin-right:1em}
  .searchwordfont {color:inherit; font-weight:bolder}
  .exp, .navi .smallfont {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 qurl(x, i)(
  (x = x.trim()) &&
  EOW + encodeURIComponent(x) +'/UTF-8/'+ (i > 1 ? '?pg='+ i : ''));
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 ok(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={qurl(q, t)} accesskey={t[0]}><b>{t}</b></a>;
  }).end();
  var [rl] = $t.find('#resultList').find('.refvocab').each(linx).end();
  cn.innerHTML = cn.className = '';
  ($(cn)
   .append(
     $('<div class="navi"><div class="q">'+ q +'</div></div>')
     .append(pn, $t.find('#itemsNumber').contents()))
   .append($t.find('.sas').find('a[href^="javascript:"]').each(idiomx).end())
   .append(rl));
  pn.addEventListener('focus', function ej_onfocus(e){
    let(b = e2b(e)) b && go(b.value);
  }, true);
  if(rl) rl.ondblclick = wclix;
}
function e2b(e){
  var b = e.target;
  if(b.nodeName !== 'BUTTON') return null;
  e.preventDefault();
  e.stopPropagation();
  b.blur();
  b.disabled = true;
  return b;
}
function idiomx(){
  with(this) if(~href.indexOf('changeIdiom')){
    parentNode.removeChild(previousSibling);
    parentNode.removeChild(this);
  } else href = qurl(''+ /".*?"/(href));
}
function linx(){
  var txt = this.textContent;
  this.innerHTML = txt.link(qurl(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, 0, .3)
            for each(w in Array.slice(words, 1))]);
        }}));
      return ss;
    },
  },
  execute: function ej_execute(args){
    Utils.openUrlInBrowser(qurl(args.object.text) || EOW);
  },
  preview: function ej_preview(pb, args, url, page){
    var cn, doc = pb.ownerDocument;
    while(!(cn = doc.getElementById(Name))) pb.innerHTML = Base;
    var u = url || qurl(args.object.text, page);
    if(!u) return;
    cn.className = 'loading';
    CmdUtils.previewAjax(pb, {
      url: u,
      success: function ej_success(htm){
        ok(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 = 10;
        for each(let a in Array.slice(cn.querySelectorAll(sb))){
          let b = doc.createElement('button');
          b.textContent = b.accessKey = i.toString(36);
          b.addEventListener('focus', ej_inline, true);
          a.parentNode.insertBefore(b, a);
          if(++i > 35) break;
        }
        function ej_inline(e){ ej_preview(pb, args, e2b(e).nextSibling.href) }
      },
      error: function ej_error(x, s){ ng(cn, x.status, x.statusText) },
    });
  },
  author: 'satyr', license: 'MIT',
});