Exit Full View

Ebay Thumbnails Greasemonkey

Ebay is very broken. I use the middle mouse button to open links in a new tabs, and I use that feature a lot in ebay. However, if you try this on a thumbnail image, you will find that it doesn't work!

Greasemonkey to the rescue! I've replaced the broken links, so that they work correctly (just as the item's description do).

Test URLs :

// ==UserScript==
// @name           ebay thumbnails
// @namespace      nickthecoder
// @description    Allows the images in search results to be middle clicked. Man, ebay is shite!
// @include        http://shop.ebay.co.uk/*
// @include        http://ebay.co.uk/*
// @include        http://business.shop.ebay.co.uk/*
// ==/UserScript==

// Please change the version before every modification
var version = 1.0;

// Add stubs for logging if firebug isn't enabled on this browser
if ( ! console ) {
  console = new Object();
  var doNothing = function() {};
  console.debug = console.info = console.log = doNothing;
}
console.debug( "begin greasemonkey script ebay_thumbnail_fix" );


function ntc_fixThumbnails()
{
  var changedATags = [];
  var aTags = document.getElementsByTagName( "a" );
  
	
  for ( var i = 0; i < aTags.length; i ++ ) {
    aTag = aTags[ i ];
    if (aTag.className == "img") {
      var parent = aTag.parentNode.parentNode;
      var otherATags = parent.getElementsByTagName( "a" );

      for ( var j = 0; j < otherATags.length; j ++ ) {
        var otherATag = otherATags[j];
        if ( otherATag.className == "vip" ) {
          aTag.href = otherATag.href;
          changedATags[ changedATags.length ] = aTag
        }
      }
    }
  }   

  // alert( "Replaced " + changedATags.length );

  // Add greasemonkey logos to the changed thumbnails

  var logo = '<div style="position:absolute; right: 0"><a href="http://nickthecoder.co.uk/pinkwino/view/Ebay+Thumbnail+Greasemonkey" title="Greasemonkey Extension"><img src="http://nickthecoder.co.uk/pinkwino/media/greasemonkey.png" alt="gm"/></a></div>';

  for ( i = 0; i < changedATags.length; i ++ ) {
    var div = document.createElement("div");
    div.innerHTML = logo;
    changedATags[i].parentNode.insertBefore( div, changedATags[i] );
    div.style.position = "relative";
  }

}

ntc_fixThumbnails();

console.debug( "end greasemonkey script ebay_thumbnail_fix" );