root/lang/javascript/userscripts/associatethis.user.js

Revision 26732, 1.9 kB (checked in by yoko, 14 months ago)

毎回リクエストしてるのは無駄なので使う時にボタンを押すように変更

Line 
1// ==UserScript==
2// @name        Associate This
3// @namespace   http://carbonfairy.org/ns/userscripts
4// @include     http://www.amazon.co.jp/*
5// @include     http://amazon.co.jp/*
6// @version     0.4.1
7// @license     MIT License
8// ==/UserScript==
9
10new function() {
11        var w = typeof unsafeWindow != 'undefined' ? unsafeWindow : window;
12        var $ = w.jQuery;
13
14        if (!w.asin || !$) return;
15        var container = $('.buyingDetailsGrid');
16        if (!container.length) return;
17
18        $('<tr><td id="associate-this"><button>Associate This</button></td></tr>')
19                .appendTo(container)
20                .find('td').css('text-align', 'center')
21                        .find('button')
22                                .click(function() {
23                                        var uri = 'http://pipes.yahoo.com/pipes/pipe.run';
24                                        var q = {
25                                                AWSAccessKeyId: '17WV92D5WX2R1VET0H02',
26                                                AssociateTag  : 'clothfairy-22',
27                                                ItemId        : w.asin,
28                                                _id           : 'DM6ru9_R3BGmxGU9xAnzeQ',
29                                                _render       : 'json'
30                                        };
31
32                                        $.getJSON(uri+'?_callback=?', q, function(data) {
33                                                var item = data.value.items[0].Items.Item;
34                                                var code = [
35                                                        '<ul class="drop">\n',
36                                                        '<li><a href="http://www.amazon.co.jp/o/ASIN/'+item.ASIN+'/'+q.AssociateTag+'/ref=nosim">#{content}</a></li>\n',
37                                                        '</ul>'
38                                                ].join('');
39                                                var title = escapeTag(item.ItemAttributes.Title);
40                                                code = code.replace(
41                                                        '#{content}',
42                                                        item.SmallImage ?
43                                                                '<img src="'+item.SmallImage.URL+'" alt="'+title+'" width="'+item.SmallImage.Width.content+'" height="'+item.SmallImage.Height.content+'"/>' :
44                                                                title
45                                                );
46
47                                                $('<textarea/>')
48                                                        .replaceAll('#associate-this')
49                                                        .css({
50                                                                width : '90%',
51                                                                height: '100px',
52                                                                margin: '3px 5%'
53                                                        })
54                                                        .text(code);
55                                        });
56
57                                        return false;
58                                });
59
60        function escapeTag(str) {
61                return str
62                        .replace(/&/g, '&amp;')
63                        .replace(/"/g, '&quot;')
64                        .replace(/</g, '&lt;')
65                        .replace(/>/g, '&gt;');
66        }
67};
Note: See TracBrowser for help on using the browser.