gist: 29674 Download_button fork
public
Description:
[Ubiquity] Amazon.co.jp
Public Clone URL: git://gist.github.com/29674.git
jamazon.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
const Name = 'jamazon',
Jamazon = 'http://www.amazon.co.jp/',
ItemMax = 35,
Base = <div class={Name}><style><![CDATA[
  $ol, $ul {margin:0; padding:0; list-style:none}
  $button {padding:0; border-width:1px;
    font:bold 96% "Consolas",monospace}
  $.item img {float:right; border:none; margin:0 0.2em 0.2em 0}
  $.num, $.price {font-weight:bold}
  $.num, $li {margin:0 0 0.2em}
  $.price {white-space:nowrap}
  $.price, $.author, $.label, $.features {font-size:88%}
  $.features li:before {content: "\2022 "}
  $.item {clear:both}
  $.logo {display:block; clear:both}
  $.error {font-style:oblique; line-height:1.8}
  $.loading + .logo {opacity:0.4}
  $.error + .logo {opacity:0.7}
  ]]></style><div id={Name}
> </div><a class="logo" href={Jamazon}
><img border="0" width="126" height="28"
src={'http://g-ecx.images-amazon.com/images/G/09/gno/images/general/'+
  'navAmazonLogoFooter._V28243234_.gif'}/></a></div
>.toXMLString().replace(/\$/g, '.'+ Name +' '),
Sel = '#'+ Name,
noun_type_jamazon_category = {
  _name: 'category 分類',
  list: [{text: t, data: d, summary: s} for([, [s, t, d]] in Iterator([
    ['Blended すべて', 'Blended', 'aps'],
    ['Apparel アパレル&ファッション雑貨', 'Apparel', 'apparel'],
    ['Baby ベビー&マタニティ', 'Baby', 'baby'],
    ['Beauty コスメ', 'Beauty', 'beauty'],
    ['Books 和書', 'Books', 'stripbooks'],
    ['Classical クラシック音楽', 'Classical', 'classical'],
    ['DVD DVD', 'DVD', 'dvd'],
    ['Electronics 家電&カメラ', 'Electronics', 'electronics'],
    ['ForeignBooks 洋書', 'ForeignBooks', 'english-books'],
    ['Grocery 食品&飲料', 'Grocery', 'grocery'],
    ['HealthPersonalCare ヘルス&ビューティー', 'HealthPersonalCare', 'hpc'],
    ['Kitchen ホーム&キッチン', 'Kitchen', 'kitchen'],
    ['Music ミュージック', 'Music', 'popular'],
    ['Software PCソフト', 'Software', 'software'],
    ['SportingGoods スポーツ&アウトドア', 'SportingGoods', 'sporting'],
    ['Toys&Hobbies おもちゃ&ホビー', 'Toys', 'toys'],
    ['VHS ビデオ', 'VHS', 'vhs'],
    ['VideoGames ゲーム', 'VideoGames', 'videogames'],
    ['Watches 時計', 'Watches', 'watch'],
  ]))],
  default: function() this.list[0],
  suggest: function(txt, htm, cb, sx){
    if(sx || !txt) return [];
    try { var re = RegExp(txt, 'i') } catch(e){ re = /^/ };
    var ss = this.list.filter(function(x) re.test(x.summary)), [s] = ss;
    if(s) this.default = function() s;
    return s ? ss : this.list;
  },
};
function hmm(c){
  c.textContent = Array.slice(arguments, 1).join(' ');
  c.className = 'error';
}
function joinq($, sel, delim)
  $.find(sel).map(function() this.textContent).get().join(delim || ' ');
function onfocus(e){
  var b = e.target;
  if(b.nodeName !== "BUTTON") return;
  b.blur();
  b.disabled = true;
  Utils.openUrlInBrowser(b.value);
}
CmdUtils.CreateCommand({
  name: 'jamazon',
  icon: Jamazon +'favicon.ico',
  description: 'Amazon.co.jp'.link(Jamazon),
  takes: {'?': noun_arb_text},
  modifiers: {in: noun_type_jamazon_category},
  execute: function({text}, {in: {data}}){
    Utils.openUrlInBrowser(
      Jamazon +'s/ref=nb_ss_?tag=matyr-22&__mk_ja_JP='+
      '%E3%82%AB%E3%82%BF%E3%82%AB%E3%83%8A&url=search-alias%3D'+ data +
      '&field-keywords='+ encodeURIComponent(jQuery.trim(text)));
  },
  preview: function(pbl, {text}, {in: {text: x}}){
    var q = Utils.trim(text);
    do var [C] = jQuery(Sel, pbl); while(!C && (pbl.innerHTML = Base));
    if(!q) return;
    C.className += ' loading';
    CmdUtils.previewAjax(pbl, {
      url: 'http://xml-jp.amznxslt.com/onca/xml',
      data: {
        Service: 'AWSECommerceService',
        AWSAccessKeyId: '0SP5F78NM10ZVNWWG482',
        AssociateTag: 'matyr-22',
        Version: '2008-08-19',
        Operation: 'ItemSearch',
        Condition: 'All',
        Merchant: 'All',
        ResponseGroup: 'ItemAttributes,Images',
        SearchIndex: x,
        Keywords: q,
      },
      dataType: 'text',
      success: function(xml){
        var res = XML(xml.replace(/<\?[^>]*>/, '')
                      .replace(/ xmlns=".*?"/g, '')),
        em = res..Error.Message;
        if(em[0]) return hmm(C, em);
        var ol = <ol/>, i = 1;
        for each(var it in res.Items.Item){
          var img = it..SmallImage[0],
          attr = it.ItemAttributes,
          price = attr.ListPrice,
          url = it.DetailPageURL +'',
          key = i.toString(ItemMax + 1).toUpperCase(),
          author = [x for each(x in attr.Author)].join(', '),
          label = attr.Label +'',
          features = ([x for each(x in attr.Feature)]
                      .reduce(function(ul, f) ul.appendChild(<li>{f}</li>),
                              <ul class="features"/>));
          ol.appendChild(
            <li class="item">{img ? <img
              src={img.URL} width={img.Width} height={img.Height}/> : ''}
            <button value={url} accesskey={key}>{key}</button>
            <a href={url}><span class="title">{attr.Title +''}
            </span></a><span class="price">{price.FormattedPrice +''}
            </span>{author && <div class="author">{author}</div>}
            {label && <div class="label">{label}</div>}
            </li>.appendChild('li' in features ? features : ''));
          if(++i > ItemMax) break;
        }
        C.innerHTML =
          <div class="num">Total:{res.Items.TotalResults}</div> + ol;
        C.addEventListener('focus', onfocus, true);
        C.className = '';
      },
      error: function(x, s, e){
        hmm(C, x.status, x.statusText, '('+ s +')');
      },
    });
  },
  previewDelay: 222,
  author: 'satyr', license: 'MIT',
});
 

Owner

satyr

Revisions