4 <name>amazon_simple_uri</name>
5 <description>Copy Amazon Simple URI.</description>
6 <description lang="ja">シンプルなAmazon URIをクリップボードにコピーします。</description>
7 <author mail="from.kyushu.island@gmail.com" homepage="http://iddy.jp/profile/from_kyushu">from_kyushu</author>
10 <minVersion>1.2</minVersion>
11 <maxVersion>2.1</maxVersion>
12 <updateURL>https://github.com/vimpr/vimperator-plugins/raw/master/amazon_simple_uri.js</updateURL>
17 let g:amazon_asamashi = "hogehoge-22"
19 と設定することにより、Amazon アソシエイトID(上の例ではhogehoge-22)をURLに追加します。
27 // URLを正規表現でチェックしてISBNっぽい10桁,13桁の数字と取り出す
30 var regex = new RegExp("([0-9]{9,13}[0-9Xx])");
31 var match = uri.match(regex);
33 if (isbn.length == 13)
35 isbn = getIsbn10(isbn);
40 // SSBのAPIを使ってISBNから書籍情報を取得
41 function getBookInfo(isbn)
43 var uri = "http://stack.nayutaya.jp/api/book/";
44 if (isbn.length == 10)
46 uri += "isbn10/" + isbn + ".json";
48 else if (isbn.length == 13)
50 uri += "isbn13/" + isbn + ".json";
52 var xhr = new XMLHttpRequest();
53 xhr.open('GET', uri, false);
55 if (xhr.status != 200) {
56 liberator.echoerr('false');
59 return window.eval('(' + xhr.responseText + ')');
62 //SSBのAPIから書籍情報を取り、そこからISBN10を取得
63 function getIsbn10(isbn13)
65 var info = getBookInfo(isbn13);
66 return info.response.book.isbn10;
69 commands.addUserCommand(
71 'Copy Amazon Short URI',
74 var asin = window.content.document.getElementById('ASIN');
75 // ASINが取得できなかった場合 / Amazon以外の書籍情報ページから取得する場合
78 asin = getIsbn(buffer.URL);
85 var uri = "http://www.amazon.co.jp/dp/" + asin + "/";
86 var asamashi = typeof liberator.globalVariables.amazon_asamashi == "undefined" ? '' : liberator.globalVariables.amazon_asamashi;
91 util.copyToClipboard(uri);
92 liberator.echo("[ASC] Copy to clipboard.");