-
Notifications
You must be signed in to change notification settings - Fork 1
/
tombloo.service.extractors.amazon.extract.js
49 lines (40 loc) · 1.55 KB
/
tombloo.service.extractors.amazon.extract.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
/**
* tombloo.service.extractors.amazon.extract.js
*
* † Amazon 関連のポスト時に起こるタイトルの問題を修正する
*
* @version 0.04
* @date 2011-08-26
* @author asiamoth <asiamoth+github@gmail.com>
* - Blog : http://asiamoth.com/mt/
* - Twitter : http://twitter.com/asiamoth
* - Tumblr : http://memo.asiamoth.com/
* http://news.asiamoth.com/
* http://ero.asiamoth.com/
* @license Same as Tombloo
* @updateURL https://github.com/asiamoth/Tombloo-patches/raw/master/tombloo.service.extractors.amazon.extract.js
*
* Tombloo: https://github.com/to/tombloo/wiki
*/
(function (undefined) {
Tombloo.Service.extractors.Amazon.extract = function (ctx) {
var asinTitle = $x('id("btAsinTitle")'),
// 「著者ページを見る」リンクがある場合に対応
xpath = ['id("handleBuy")/div[@class="buying"]/span//a/text()',
'id("handleBuy")/div[@class="buying"]/a/text()'].join('|'),
// 01_utility.js: function $x(exp, context, multi)
// multi にして複数の著作者名をすべて「配列で」取得
author = $x(xpath, currentDocument(), true);
ctx.href = this.normalizeUrl(ctx.host, this.getAsin(ctx));
if (asinTitle) {
ctx.title = 'Amazon: ' + convertToPlainText(asinTitle);
// javascript: if ([]) {alert('true')} // 空の配列は true
if (author.length !== 0) {
ctx.title += ': ' + author.join(', ');
}
} else {
// 単純にページのタイトルのままで post する
ctx.title = ctx.title;
}
};
})();