const Name = 'jamazon',
Jamazon = 'http://www.amazon.co.jp/',
ItemMax = 35,
Logo =
,
Base = ''+
.appendChild(Logo),
Categories = {
'All すべて': ['All', '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'],
'Shoes&Bags シューズ&バッグ': ['Shoes', 'shoes'],
'Software PCソフト': ['Software', 'software'],
'SportingGoods スポーツ&アウトドア': ['SportingGoods', 'sporting'],
'Toys&Hobbies おもちゃ&ホビー': ['Toys', 'toys'],
'VHS ビデオ': ['VHS', 'vhs'],
'VideoGames TVゲーム': ['VideoGames', 'videogames'],
'Watches 時計': ['Watches', 'watch'],
};
function ng(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);
}
function percentize(c) '%'+ c.charCodeAt().toString(16);
function amazEnc(str)(
encodeURIComponent(str).replace(/[!*\'()]/g, percentize));
function amazSig(endp, reqp, params){
var ps = $.extend({
Timestamp: new Date().toISOString().slice(0, -5) +'Z',
AssociateTag: 'matyr-22',
AWSAccessKeyId: '0SP5F78NM10ZVNWWG482',
SignatureMethod: 'HmacSHA256',
SignatureVersion: 2,
}, params);
var sps = [k +'='+ amazEnc(ps[k]) for(k in ps)].sort().join('&');
return ('http://'+ endp + reqp +'?'+ sps +'&Signature='+
amazEnc(Utils.signHMAC('SHA256',
'DlSRkBtC3WDAMjA5fVJO4Fg04omvXYVXs49oNPlo',
['GET', endp, reqp, sps].join('\n'))));
}
CmdUtils.CreateCommand({
name: 'jamazon',
icon: Jamazon +'favicon.ico',
description: ''+ Logo,
help: ('[ Categories カテゴリリスト ]'+
[- {c}
.toXMLString() for(c in Categories)].join('') +
'
'),
arguments: {
object: noun_arb_text,
format: CmdUtils.NounType('category カテゴリ', Categories, 'All'),
},
execute: function jam_execute({object: {text}, format: {data}}){
Utils.openUrlInBrowser(
(text = Utils.trim(text))
? (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[1] +
'&field-keywords='+ encodeURIComponent(text))
: Jamazon);
},
preview: function jam_preview(pb, {object: {text}, format: {data}}){
do var cn = pb.ownerDocument.getElementById(Name);
while(!cn && (pb.innerHTML = Base));
if(!text) return;
cn.className += ' loading';
CmdUtils.previewAjax(pb, {
url: amazSig('xml-jp.amznxslt.com', '/onca/xml', {
Service: 'AWSECommerceService',
Version: '2008-08-19',
Operation: 'ItemSearch',
Condition: 'All',
Merchant: 'All',
ResponseGroup: 'ItemAttributes,Images',
SearchIndex: data[0],
Keywords: text,
}),
dataType: 'text',
success: function jam_success(xml){
var res = XML(xml.replace(/^\s*<\?[^>]*>/, '')
.replace(/ xmlns=".*?"/g, '')),
em = res..Error.Message;
if(em[0]) return ng(cn, em);
var 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)],
li = (
{attr.Title +''}
{price.FormattedPrice +''}
);
img && li.prependChild(
);
author && li.appendChild({author}
);
label && li.appendChild({label}
);
features.length && li.appendChild(
features.reduce(function(ul, f) ul.appendChild({f}),
));
ol.appendChild(li);
if(++i > ItemMax) break;
}
cn.innerHTML =
Total: {res.Items.TotalResults}
+ ol;
cn.addEventListener('focus', onfocus, true);
cn.className = '';
},
error: function jam_error(x, s){
ng(cn, x.status, x.statusText, '('+ s +')');
},
});
},
author: 'satyr', license: 'MIT',
});