Skip to content

Instantly share code, notes, and snippets.

@tsupo
Created May 8, 2009 18:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tsupo/108923 to your computer and use it in GitHub Desktop.
Save tsupo/108923 to your computer and use it in GitHub Desktop.
replace image to 'no-image-exists' image of Amazon item, if not exists image of this item
/*
* Amazon の商品画像があればそのまま表示し、なければ「画像がありません画像」を
* 表示するスクリプト
*
* written by H.Tsujimura 2005, 2006, 2007
*/
/* img の onload に replaceImage を埋め込む必要があるバージョン */
/* → いずれ、この replaceImage は廃止し、replaceImageForAmazon に移行する */
function replaceImage(img,rep_img) {
if (img.width == '1' && img.src.match(/\.01\./)) {
img.src = rep_img;
}
else if (img.width == '1') {
img.src = img.src.replace('.09.','.01.');
}
}
/* img の onload に replaceImage を埋め込まなくてもよいバージョン */
function replaceImageForAmazon(img,rep_img) {
if (img.width == '1' && img.src.match(/\.01\./)) {
img.src = rep_img; // 『「画像がありません」画像』を代替画像とする
}
else if (img.width == '1') {
img.src = img.src.replace('.09.','.01.');
// *.09.* 画像の代用として *.01.* を採用する
if (img.width == '1')
img.src = rep_img;
}
}
function replaceImageForHatena(img,rep_img) {
if ( (img.height != "13") && (img.height != "1") ) {
/* はてながメンテ中の場合は、代替画像を表示する */
img.src = rep_img;
img.width = "1";
img.height = "1";
}
}
window.onload = function(){
oElements = document.getElementsByTagName("img");
for (i = 0; i < oElements.length; i++) {
if ( oElements[i].src.match("http://images-jp.amazon.com/images/") )
replaceImageForAmazon(oElements[i],"http://images-jp.amazon.com/images/G/09/icons/no-img-sm.gif");
else if ( oElements[i].src.match("http://b.hatena.ne.jp/entry/image/") )
replaceImageForHatena(oElements[i],"http://watcher.moe-nifty.com/memo/images/no-img-bm.gif");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment