eBay - Completed Items

By Keith Hopkins Last update Oct 6, 2008 — Installed 1,069 times.

There are 3 previous versions of this script.

// eBay Completed Items ~ Version 1.3
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Coder: Keith Hopkins
//
// ==UserScript==
// @name          eBay - Completed Items
// @description   This script adds link to the completed items search using the auction title for currently viewed item
// @namespace     
// @include       http://*.ebay.tld/*
// ==/UserScript==
/*
This script is designed to help you easly find the price of completed items that match the item you are looking at on eBay
Works out average price for items that have sold
Version History
1.3 - Fixed title and Popup  Window bug
1.2 - Works out average for Completed Items
1.1 - Auction Title is now Editable
*/
var popupwin = 1; //POPUP WINDOW
var node
var idLoc = location.pathname.indexOf("QQitemZ");
var itemId, endLoc;
if (idLoc != -1) 
{
	idLoc += 7;
	endLoc = location.pathname.indexOf( "QQ", idLoc );
	itemId = location.pathname.substring( idLoc, endLoc );
} else {
	idLoc = location.search.indexOf("&item=");
	if ( idLoc != -1 ) 
	{
	idLoc += 6;
	var endLoc = location.search.indexOf( "&", idLoc );
	    if ( endLoc <= idLoc ) 
		{
		endLoc = location.search.length;
		}
		itemId = location.search.substring( idLoc, endLoc );
	}
}

var search,watchLink;
try
{
search = document.getElementsByTagName("h1")[1].textContent;
}
catch(err)
{
//alert(err+'\n'+search);
}


for ( var i = 0; i < document.links.length; i++ ) 
{
		if ( document.links.item(i).href.indexOf( "ShowEmailAuctionToFriend" ) != -1 ) {
			watchLink = document.links.item(i);
			break;
		}
}
		
	searchUrl = "http://search.ebay.co.uk/ws/search/SaleSearch?satitle=" + search +"&fis=2"
	
if (watchLink != null ) 
{
var completed = document.createElement("a");
    if (popupwin==1)
    {
	completed.addEventListener("click", popup, false); 
	completed.href = '#';
    } else {
	completed.href = searchUrl;
	completed.target = "_GM";
    }
completed.title = "Find Completed Auctions for: " + search;
watchLink.parentNode.insertBefore(completed, watchLink.nextSibling);
completed.appendChild(document.createTextNode("| View Completed Items |"));

} else {
// Excape if no item number is found
}

//alert('Item# ' + itemId + '\nTitle ' + search + '\n' + watchLink);

//Average
var allLinks, thisLink;
allLinks = document.evaluate(
    
    "//td[@class='prices bidsold g-b']",
    document,
    null,
    XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE,
    null);

var averagePrice = 0.00;
var price;
for (var i = 0; i < allLinks.snapshotLength; i++) {
    thisLink = allLinks.snapshotItem(i);
    var price = thisLink.innerHTML;
    price = price.replace("£","");
    price = price.replace("<i>","");
    price = price.replace("</i>","");
    price = parseFloat(price);
    averagePrice = averagePrice + price;
    
    }
if (averagePrice > 1) {
averagePrice = averagePrice/i;
alert("Average Price: " + averagePrice); 
}
function popup() {
input = prompt("Completed item Search Term",search);
    if(input!=null)
    {
    searchUrl = "http://search.ebay.co.uk/ws/search/SaleSearch?satitle=" + input +"&fis=2";
    window.open(searchUrl, '', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=826,height=430,left=124,top= 84');
    }
}