PE2HO

Betelgeuse's Diary

スポンサーサイト

上記の広告は1ヶ月以上更新のないブログに表示されています。
新しい記事を書く事で広告が消せます。

Amazonの画像加工(応用編5) AmazonのRSS取得と、画像表示を組み合わせる・3

 
以前に扱ったものを改造して、左に設置してみました。
ページを読み込みなおすたびに変わります。
色々なノードを詰め込んでいるので、「新着がない」「ベストセラーがない」などの理由で表示できないもの、エラーとなるものもたくさんあります。
実際に使う場合は、自分の使いたいものだけデータを削ったり追加したりしてみてください。
追記:ここからかなり大幅にいじっていますので、最新のものはソース内を眺めてみてください


ブログ記事内からJavaScriptでAmazonのRSSを取得し、表示する(Google Ajax Feeds API利用)
ブログ記事内からニコニコ動画の公開RSSを取得し表示する(Google Ajax Feeds API利用)
Amazonの画像加工(応用編2) AmazonのRSS取得と、画像表示を組み合わせる
Amazonの画像加工(応用編3) AmazonのRSS取得と、画像表示を組み合わせる・2
【激重注意】ニコニコ動画の公開RSSをすべて表示するテスト
ブログ記事内からJavaScriptでTwitterのRSSを取得し、表示する(Google Ajax Feeds API利用)

画像が存在しない場合の差し替えには以下を利用させていただきました。ありがとうございます
JavaScript で、画像本来のサイズ(幅, 高さ)を取得する方法 - latest log

1. 以下のソースをコピペ
2. Googleにログインした状態で、自サイト/ブログのURLでキーをもらう
3. key= 以降を差し替え [YOUR GOOGLE KEY]
4. アソシエイトIDを入れ替えるのもお忘れなく [YOUR AMAZON TRACKING ID]
5. fc2ブログならばブログ本文で「改行の扱い 」を「HTMLタグのみ」にチェックか
 「プラグインの設定」で「公式プラグイン追加」から「フリーエリア」を追加して貼り付け
6. 動くはず
7. カスタマイズ用の資料:クラス リファレンス - Google AJAX Feed API - Google Code


<script type="text/javascript" src="http://www.google.com/jsapi?key=[YOUR GOOGLE KEY]"></script>

<script type="text/javascript">
function amazonLoadImage(image, url1, url2 ){
    image.src=url1;
    image.onload=function(){
        var size=getActualDimension(this);
        if( size.width==1 && size.height==1 ){
            image.src=url2;
        }
    };
}

// http://d.hatena.ne.jp/uupaa/20090602/1243933843
function getActualDimension(image){
  var run, mem, w, h, key = "actual";
 
  // for Firefox, Safari, Google Chrome
  if ("naturalWidth" in image) {
    return { width:  image.naturalWidth,
             height: image.naturalHeight };
  }
 
  if ("src" in image) { // HTMLImageElement
    if (image[key] && image[key].src === image.src) {
      return image[key];
    }
    if (document.uniqueID) { // for IE
      run = image.runtimeStyle;
      mem = { w: run.width, h: run.height }; // keep runtimeStyle
      run.width  = "auto"; // override
      run.height = "auto";
      w = image.width;
      h = image.height;
      run.width  = mem.w; // restore
      run.height = mem.h;
    } else { // for Opera and Other

      mem = { w: image.width, h: image.height }; // keep current style
      image.removeAttribute("width");
      image.removeAttribute("height");
      w = image.width;
      h = image.height;
      image.width  = mem.w; // restore
      image.height = mem.h;
    }
    return image[key] = { width: w, height: h, src: image.src }; // bond
  }
  // HTMLCanvasElement
  return { width: image.width, height: image.height };
}


var _doc=document;
var amazonid="[YOUR AMAZON TRACKING ID]";
google.load("feeds", "1");

// items in amazon.co.jp
var CategoryList=["new-releases","bestsellers","most-wished-for","most-gifted"];
var NodeList2=[
{"Ct":"diy", "Nid":["0"]},

{"Ct":"dvd", "Nid":["0", "562016","562014","562020","562018","16286781","16286931","12842371","12842321","562022","562024","562026","564522","562030","16378461"]},
{"Ct":"dvd", "Nid":["896246"]},

{"Ct":"dmusic", "Nid":["digital-music-album","2129353051"]},
{"Ct":"dmusic", "Nid":["digital-music-track","2129372051"]},

{"Ct":"toys", "Nid":["0","15691661","13321671","13321701","13321721","13364681","13365361","13365171","13321821","13321831","13321841","13321851","13321761","13321731","13321741","13321751","594535051","13321791","13321801","13321811","13321681","13321691","13321781","13321771","16382311","13321861"]},

{"Ct":"automotive", "Nid":["0"]},

{"Ct":"videogames", "Nid":["0","15782591","637874","637876","13305031","193662011","637878","637880","637882","13305831","15783221","639096","637886","637850","13306431","639122"]},

{"Ct":"beauty","Nid":["0","52905051","52906051","52907051","52908051","52909051","52910051","52911051","52912051","52913051"]},

{"Ct":"shoes", "Nid":["0"]},

{"Ct":"jewelry","Nid":["0","86228051","86233051","86239051","86240051","86241051","86242051","86243051","86244051","86245051","86246051","86249051","86252051","87162051","87839051"]},

{"Ct":"sporting-goods","Nid":["0","14315441","14315411","14315521","15337751","14315531","14315431","14315511","14315421","14315501","15407321","14315461","14315451","14315551","14315491","14315541","15407331","14315471"]},

{"Ct":"software","Nid":["0","689132","16245011","1040116","637648","16250561","16250691","637644","637662","637652","10929921","16250751","16250861","637650","1040106","637666","3137861","10929641"]},
{"Ct":"software","Nid":["927712","927714","927716","927718","382742011","382743011","382744011","382745011","10929851","10929911"]},

{"Ct":"computers", "Nid":["0"]},

{"Ct":"video", "Nid":["0"]},

{"Ct":"hpc","Nid":["170432011","362572011","169642011","169944011","325817011","170563011","170680011","172509011"]},
{"Ct":"hpc","Nid":["171288011","290175011","86700051","86701051","86702051","86703051"]},

{"Ct":"baby", "Nid":["0","345963011","345991011","345939011","345891011","345889011","345905011","345914011","345931011","345953011","345971011","345977011","88723051"]},

{"Ct":"pet-supplies", "Nid":["0"]},

{"Ct":"kitchen", "Nid":["0","13938481","13938491","13938501","13938521","490286011","13944851","13938531","13938541","13945081","16428011","16428221","13945061","13946831","13945071","16225511","13945231","13945201","345119011","13945211","15357281","15357291","15357301","15357311","15357321","393022011","515408011","86914051","124048011","3895771","3895791","3895761","4082801","3895801","13944851","3895741","3895751"]},

{"Ct":"electronics","Nid":["0","16462091","16462081","3477381","3371341","3371351","3371361","3371381","3371401","3483101","3371421","3371391","3371461","128187011","171370011"]},

{"Ct":"office-products","Nid":["0","89083051","89084051","89085051","89086051","89087051","89088051","89089051","89090051","89091051"]},

{"Ct":"watch", "Nid":["0"]},

{"Ct":"apparel", "Nid":["0","88383051","368062011","362793011","362794011"]},

{"Ct":"books", "Nid":["0","466284","571582","571584","492152","466286","466282","492054","466290","492166","466298","466294","466292","492228","466304","492020","466302","3148931","466306","466280","500592","492266","466296","466300","13384021","746102","255460011","886928","13383771","10667101","10667181"]},
{"Ct":"books", "Nid":["10667101","10667181","10667161","10667111","15826441","10667271"]},

{"Ct":"musical-instruments", "Nid":["0"]},

{"Ct":"english-books", "Nid":["0"]},

{"Ct":"music","Nid":["0","569170","569172","569290","569292","569294","569298","562050","569318","569320","569322","562052","701040","562056","562064","562058","562060","562062","569174","569186","899296","3032511"]},

{"Ct":"english-books", "Nid":["0"]},

{"Ct":"food-beverage","Nid":["0"]}
];

var AmazonImageSets=[
// LARGEST IMAGE
{
 "BaseUrl1":"http://images.amazon.com/images/P/",
 "BaseUrl2":".09.MAIN.",
 "BaseUrl3":"_SS1500",
 "BaseUrl4":"_SCRMZZZZZZ_.jpg",
  "Size":"170,200",
  "Move1":"_CR700,700,",
  "Move2":"_SS200,",
  "Effect1":"_BL20",
  "Effect2":"_BL0",
  "Effect3":"_BL1"
},
//500px
{
 "BaseUrl1":"http://images.amazon.com/images/P/",
 "BaseUrl2":".09.MAIN.",
 "BaseUrl3":"_SS500",
 "BaseUrl4":"_SCLZZZZZZZ_.jpg",
  "Size":"170,200",
  "Move1":"_CR200,100,",
  "Move2":"_CR200,110,",
  "Effect1":"_BL20",
  "Effect2":"_BL0",
  "Effect3":"_HL0,0,170,200,257"
},
//200px
{
 "BaseUrl1":"http://images.amazon.com/images/P/",
 "BaseUrl2":".09.MAIN.",
 "BaseUrl3":"_SS200",
 "BaseUrl4":"_SCLZZZZZZZ_.jpg",
  "Size":"170,200,",
  "Move1":"_CR20,0,",
  "Move2":"_CR22,0,",
  "Effect1":"_BL20",
  "Effect2":"_BL0",
  "Effect3":"_SH94_BL4"
}
];


function initialize_left() {
    var container = _doc.getElementById("feedxx") ,
    link = _doc.getElementById("rssurl_left"),
    rand0 = Math.floor(Math.random()*CategoryList.length),
    rand1 = Math.floor(Math.random()*NodeList2.length),
    rand2 = Math.floor(Math.random()*NodeList2[rand1].Nid.length),
    rand3 = Math.floor(Math.random()*AmazonImageSets.length),
    rss_url="http://www.amazon.co.jp/rss/"+ CategoryList[rand0] +"/"
             + NodeList2[rand1].Ct + "/" + NodeList2[rand1].Nid[rand2], 
    href_title="[" + CategoryList[rand0] + "]-[" + NodeList2[rand1].Ct + "]-[" 
             + NodeList2[rand1].Nid[rand2] +"]",
    feed ;

    container.innerHTML="Loading...";
    for (var i =link.childNodes.length-1; i>=0; i--) {link.removeChild(link.childNodes[i]);}
    link.href=rss_url + "?tag=" + amazonid;

    feed = new google.feeds.Feed(rss_url); 
    feed.setNumEntries(10);

    feed.load(function(result) {
        if (!result.error) {
            container.innerHTML="";
            link.appendChild(_doc.createTextNode(result.feed.title.replace(/>/g,">")));
            link.appendChild(_doc.createTextNode("["+result.feed.entries.length+"]"));
            if( result.feed.entries.length == 1 ){
               container.innerHTML="Reloading...";
               initialize_left();
               return;
            }
            
            for (var i = 0; i <result.feed.entries.length; i++) {
                var entry = result.feed.entries[i];
                var asin = entry.link.split("/")[5];
                
                var elem = _doc.createElement("a");
                elem.href = entry.link + "?tag=" + amazonid ;
                elem.target = "_blank";
                elem.title = entry.title;

                var azimg = AmazonImageSets[rand3];
                //ASIN-BASED IMAGE URL
                var azimgURL = azimg.BaseUrl1 + asin
                   + azimg.BaseUrl2 + azimg.BaseUrl3
                   + azimg.Move1 + azimg.Size + azimg.Effect1 + azimg.BaseUrl4;

                //RSS-BASED IMAGE URL
                var rssimgURL = entry.content.split("img src=\"")[1].split("\" alt=")[0].replace("_SL160",azimg.BaseUrl3+ azimg.Move1 + azimg.Size + azimg.Effect1);

                var img = _doc.createElement("img");
                amazonLoadImage(img, azimgURL, rssimgURL );

                img.onmouseover=function(){
                   this.src=this.src.replace(azimg.Effect1,azimg.Effect2).replace(azimg.Effect3,azimg.Effect2).replace(azimg.Move1,azimg.Move2)
                };
                img.onmouseout=function(){
                   this.src=this.src.replace(azimg.Effect2,azimg.Effect3).replace(azimg.Move2,azimg.Move1)
                };

                var style="width:170px;height:200px;border: medium #090 dotted;";
                if(_doc.all) img.style.cssText=style;
                else img.setAttribute("style",style);

                elem.appendChild(img);
                container.appendChild(elem);
                container.appendChild(_doc.createElement("br"));
                container.appendChild(_doc.createTextNode(entry.title));
                container.appendChild(_doc.createElement("hr"));
            }
        } else {
            container.innerHTML="failed";
        }
    });
}
google.setOnLoadCallback(initialize_left);
</script>
<input type="button" value="CHANGE" style="width:100%; border-width:0;" onclick="initialize_left()">
<a id="rssurl_left"></a>
<div id="feedxx"></div>
<a href="http://parasiteeve2.blog65.fc2.com/blog-entry-619.html">表示方法について</a><br />
Amazonの画像加工について(まとめ)
http://parasiteeve2.blog65.fc2.com/blog-entry-33.html

関連記事
スポンサーサイト

テーマ:アフィリエイト - ジャンル:アフィリエイト



コメント

コメントの投稿


管理者にだけ表示を許可する

トラックバック

トラックバックURLはこちら
http://parasiteeve2.blog65.fc2.com/tb.php/619-03aa8920
この記事にトラックバックする(FC2ブログユーザー)

FC2Ad

上記広告は1ヶ月以上更新のないブログに表示されています。新しい記事を書くことで広告を消せます。