Hack 13 Find Similar Items


A simple JavaScript tool to quickly list
auctions similar to the one you''re looking
at.
I''m always excited to
discover something new while searching on eBay, but
I''ve been around long enough to know that
there''s virtually no such thing as
"one of a kind."
When you''ve found an item you''re
interested in, it''s often helpful to look for other
auctions for similar items, either to compare prices or perhaps to
find something better. Typically, this requires opening a search box
and typing the name of the item for which to search.
Here''s a quick hack that will eliminate these steps
and list similar items with a single click.
Create a new button on your browser''s Links bar (see Customizing the Links Bar for
details) and type the following JavaScript code, all on one line,
into the new link:
javascript:void(win=window.open(
''http://search.ebay.com/ws/search/SaleSearch?satitle=''+
document.title.substring(document.title.indexOf('' - '')+3)))
Make sure to note the capitalization of the JavaScript code, such as
the uppercase "O" in the
indexOf keyword. Note also the spaces around the
hyphen ('' - ''). You can name the new link anything
you like, such as "Find Similar."
Then, open any auction page and click the new link, as shown in Figure 2-2. (Naturally, the hack won''t
work on a non-auction page.) A new window will appear with search
results matching the title of the auction you were just looking at,
which, in theory, should contain at least one auction. At this point,
you can modify and repeat the search as needed.
Figure 2-2. View a list of similar auctions by clicking this custom button on your Links bar

Customizing the Links Bar
Modern web browsers such as Netscape, Internet Explorer, and Mozilla
all have a customizable toolbar called the
Links
bar. The Links bar, shown in Figure 2-2, is nothing
more than a small collection of easily accessible bookmarks (a.k.a.
favorites, shortcuts, links) that you can click to open the
corresponding pages.
The easiest way to add a custom button to the Links bar is to simply
drag-and-drop the URL shortcut icon (to the immediate left of the
URL) onto the bar to add the current page. Or drag any link from any
open web page, bookmark, favorite, or Internet shortcut onto the
Links bar.
Some of the hacks in this book use JavaScript code embedded in links
placed on the Links bar. Although there''s no way to
create a blank button on the Links bar into which you can type the
code, there are other easy ways to create such a link:
Start by dragging-and-dropping any arbitrary link onto the Links bar.
Then, right-click the new link, select Properties, and replace the
URL with the appropriate JavaScript code.
In Windows, right-click on an empty area of your desktop and go to
New
field, choose a name, and click Finish when you''re
done. Then, drag-and-drop the new shortcut onto the Links bar.
Create a new web page (l file) and place the
JavaScript code into an <a> hyperlink tag
(described in [Hack #40]). Then, open
the page and drag-and-drop the hyperlink onto the Links bar. This is
typically more trouble than the other two methods, but it can be an
easy way to send the link to others, especially since you can include
instructions right on the same page.
2.6.1 How It Works
The first part of the code, win=window.open,
instructs your browser to open a new window and navigate to the URL
that follows. The reason we need JavaScript at all is that part of
the URL needs to use information from the auction shown in the
current window, something a static link wouldn''t be
able to do.
Next comes the URL to open. The first part of the URL is taken from a
standard eBay search URL, as seen in [Hack #12]:
http://search.ebay.com/ws/search/SaleSearch?satitle=
The query parameter is then completed by including
the title of the currently displayed auction:
document.title.substring(document.title.indexOf('' - ''),document.title.length)
This last bit of code extracts the auction title from the page title
by taking only the text that appears after the hyphen (with spaces on
either side) that separates the end date from the auction title.
2.6.2 Hacking the Hack
By default, this hack searches only auction titles. To search both
titles and descriptions, add the
&sotextsearched=2 parameter to the URL, making
sure to place it before the &query parameter,
like this:
...SaleSearch?sotextsearched=2&satitle=
A variation of this hack might be used to search completed auctions
instead of current auctions, which may be useful for finding how
similar items have previously sold or possibly seeing if the specific
item on which you''re bidding is being resold. Just
change the URL to that of a completed item search, like this:
http://search-completed.ebay.com/search/search.dll?GetResult&query=
Note that eBay will complain if you try to show complete auctions and
search titles and descriptions at the same time, since completed
items can be searched only by their titles.