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',
});