// PLUGIN_INFO//{{{ var PLUGIN_INFO = amazon_simple_uri Copy Amazon Simple URI. シンプルなAmazon URIをクリップボードにコピーします。 from_kyushu 0.1 GPL 1.2 2.1 http://svn.coderepos.org/share/lang/javascript/vimperator-plugins/trunk/amazon_simple_uri.js || let g:amazon_asamashi = "hogehoge-22" ||< と設定することにより、Amazon アソシエイトID(上の例ではhogehoge-22)をURLに追加します。 ]]> ; //}}} // (function() { // URLを正規表現でチェックしてISBNっぽい10桁,13桁の数字と取り出す function getIsbn(uri) { var regex = new RegExp("([0-9]{9,13}[0-9Xx])"); var match = uri.match(regex); var isbn = match[0]; if (isbn.length == 13) { isbn = getIsbn10(isbn); } return isbn; } // SSBのAPIを使ってISBNから書籍情報を取得 function getBookInfo(isbn) { var uri = "http://stack.nayutaya.jp/api/book/"; if (isbn.length == 10) { uri += "isbn10/" + isbn + ".json"; } else if (isbn.length == 13) { uri += "isbn13/" + isbn + ".json"; } var xhr = new XMLHttpRequest(); xhr.open('GET', uri, false); xhr.send(null); if (xhr.status != 200) { liberator.echoerr('false'); return; } return window.eval('(' + xhr.responseText + ')'); } //SSBのAPIから書籍情報を取り、そこからISBN10を取得 function getIsbn10(isbn13) { var info = getBookInfo(isbn13); return info.response.book.isbn10; } commands.addUserCommand( ['amazoncopy','asc'], 'Copy Amazon Short URI', function(args) { var asin = window.content.document.getElementById('ASIN'); // ASINが取得できなかった場合 / Amazon以外の書籍情報ページから取得する場合 if (asin == null) { asin = getIsbn(buffer.URL); } else { asin = asin.value } var uri = "http://www.amazon.co.jp/dp/" + asin + "/"; var asamashi = typeof liberator.globalVariables.amazon_asamashi == "undefined" ? '' : liberator.globalVariables.amazon_asamashi; if (args == "+a") { uri += asamashi; } util.copyToClipboard(uri); liberator.echo("[ASC] Copy to clipboard."); } ); })(); alue='committer'>committer
path: root/memo.js
blob: 25e588c9073c86eefe7a443483ee4484d009778f (plain)
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