Amazon Large Images

By Tom W.M. Last update Aug 25, 2008 — Installed 1,270 times. Daily Installs: 1, 0, 2, 0, 1, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 3, 0, 0, 0, 0, 1, 0, 1, 0, 1, 1, 0, 0, 0, 2, 0, 1

There are 1 previous version of this script.

// This user script makes product images on Amazon.com as large as possible.

// This is primarily useful for gathering album art for your music collection, 

// but is also effective eye candy.  As a side effect all those tacky "search

// inside this book" tags are eliminated.  If you like, you can apply a custom

// formatting string, as described at http://aaugh.com/imageabuse.html.  Just 

// set the "format" pref for this script in about:config to your format string.

// This might be useful if you have a small monitor and want to limit the size

// of the images (now that would be a bit ironic, wouldn't it ;-p).

//

// This script has been tested on amazon.com, amazon.co.uk, and amazon.co.jp.



// ==UserScript==

// @name           Amazon Large Images

// @version        4

// @namespace      http://freecog.net/2006/

// @description    Makes product images on Amazon.com as large as possible.

// @include        http://*.amazon.tld/*

// @include        http://amazon.tld/*

// ==/UserScript==





/* Changelog:



Version 4, 25 August 2008:

* Fixed to work with changes to Amazon's pages.



Version 3, 17 April 2007:

* Updated the @includes--Amazon doesn't seem to require the www prefix anymore.



Version 2, 27 Feb 2007:

* Fixed a bug that caused certain customer images to not be resized.

* Fixes the issue with the text overlapping a large image.



Version 1: Initial public release



*/



const ali_DEBUG = GM_getValue('debug', false);



// If you want to set a custom format, set this with about:config.  The default

// simply shows the largest image available.  For more on these codes go to 

// http://aaugh.com/imageabuse.html.  Also note that you'll need to escape any

// regular expression metacharacters in the string you specify.

var ali_format = GM_getValue('format', '_SCLZZZZZZZ_');



// Function to replace an image URL's format specifier with `ali_format`.

function src_to_large(src) {

	var replacement = "." + ali_format + '$1.$2$3';

	return src.replace(/\._[^\.]+?_(\.L)?\.(jpe?g|gif|png)("|'|$)/, replacement);

}



var g_width = 0;

var g_height = 0;



function fix_image() {

	var img = g_container.getElementsByTagName('img')[0];

	img.removeAttribute('width');

	img.removeAttribute('height');

	img.src = src_to_large(img.src);

	img.addEventListener('load', function() {

		if (img.width > g_width || img.height > g_height) {

			g_width = Math.max(g_width, img.width);

			g_height = Math.max(g_height, img.height);

			var cell = g_container.parentNode.parentNode;

			cell.style.width = g_width + 'px';

			cell.style.height = g_height + 'px';

			if (ali_DEBUG) GM_log('Image size increased');

		}

	}, false);

	if (ali_DEBUG) GM_log("Image fixed.");

	return img;

}



// Find the product image and change its size.

var g_container = document.getElementById('prodImageCell');

if (g_container) {

	fix_image(g_container);

	g_container.style.textAlign = 'center'; // Center images

	

	// Remove size restrictions

	var node = g_container;

	while ((node = node.parentNode)) {

		[node.width, node.height] = ['', ''];

		[node.style.width, node.style.height] = ['auto', 'auto'];

		if (node.className === 'productImageGrid') {

			break;

		}

	}

} else if (ali_DEBUG) {

	GM_log("Product image not found.");

}



var g_token = null;

g_container.addEventListener('DOMSubtreeModified', function(e) {

	if (g_token !== null) window.clearTimeout(g_token);

	g_token = window.setTimeout(fix_image, 10);

}, false);