Add a Feed to My Yahoo! with a Right-Click





Add a Feed to My Yahoo! with a Right-Click

Speed up the time it takes to add RSS feeds to My Yahoo! with Internet Explorer.

Adding an RSS feed to My Yahoo! isn't a complex process, but it does involve some copying, pasting, clicking, and generally breaking out of the flow of reading a site. With a bit of browser hacking, you can reduce the friction of adding sites to My Yahoo! by adding a context menu entry.

A context menu is the menu that pops up when you right-click an element on a web page (or Ctrl-click it on a Mac). The context part of its name refers to the fact that different choices appear in different situations. For example, when you right-click a link, you have the options to "Open Link in New Window," Copy Link Location, Bookmark This Link, and others. In another context, such as when clicking an image or clicking highlighted text, you have different choices in the menu.

If you've been reading personal weblogs for a while, you've probably seen many variations of the white-on-orange XML buttons that indicate a link to an RSS feed, and if not you can find some examples [Hack #35] in this book.

Wouldn't it be great if you could right-click one of these buttons and have the option to "Add to My Yahoo!"? That would save you quite a few steps, and you wouldn't have to break from the site you're currently reading to add the feed. This hack shows how to add this context menu entry in Internet Explorer.

The Code

Much like a bookmarklet [Hack #28], any JavaScript that runs via a context menu entry has access to the page currently loaded in the browser. That means that when you click the context menu entry you've added, the browser executes a script that takes some action using information from the current page.

In this case, the action is grabbing the URL linked from the currently clicked image, constructing a special My Yahoo! URL that includes the feed URL, and opening the new URL in a new browser window.

Save the following code to a file called AddToMyYahoo.html:

	<script language="JavaScript">
	var addURL = new String("http://add.my.yahoo.com/rss?url=");

	var w = window.external.menuArguments
	var url = w.event.srcElement.parentElement.href;

	window.open(addURL + url,null,
		"height=455, width=788, status=yes, scrollbars=yes, resizable=yes");
	</script>

The external.menuArguments object holds information about the current document, and the event.srcElement is the document item the user clicked. Grabbing the HRef attribute of the element's parent will give you the link URL that is around the image tag. Save the file in a spot you'll remember. For simplicity in this hack, save it to a directory called c:\scripts\.

Now that the script is ready to go, you just need to add the context menu entry to Internet Explorer and tell it to run this particular script when you click the entry. You'll accomplish this through the Windows Registry. The Registry is a system database that holds information about applications, including Internet Explorer. You can safely make additions to the Registry via .reg files. Create a new text file called AddYahooContext.reg and add the following code:

	Windows Registry Editor Version 5.00
	[HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\MenuExt\Add to My 
Yahoo!] @="c:\\scripts\\AddToMyYahoo.html" "contexts"=dword:00000002

Backslashes, such as those in filesystem paths, must be escaped as double slashes (\\) in Registry entry files.


Note that the contexts entry here ends with 2, which means the entry will appear only when the user has clicked an image. Other values you could use here include 1 (for anywhere), 20 (for text links), or 10 (for text selections).

Save the file, double-click it, and confirm that you want to add the new Registry information. You'll now have a right-click menu entry called "Add to My Yahoo!" whenever you right-click an image.

Running the Hack

Once the code and Registry settings are in place, restart Internet Explorer. Browse to a site with a feed URL link and take the new context menu entry for a spin. When you right-click an image, you should see "Add to My Yahoo!," as shown in Figure.

When you click the "Add to My Yahoo!" menu entry, a window like the one shown in Figure should appear with the My Yahoo! feed preview page.

Keep in mind that the "Add to My Yahoo!" context menu entry will be available for every image on a web page, regardless of whether or not it links to an RSS feed. So you'll have to use your best judgment about when to use the feature. If the image turns out not to be linked to an RSS feed, the Yahoo! feed preview page will let you know quickly. If you don't see posts in the preview box on the right side of the page, you'll know that a feed won't be added to My Yahoo! if you click the Add button.

"Add to My Yahoo!" context menu entry


Once you're finished adding the feed, you can simply close the pop-up window and go back to reading the site.



 Python   SQL   Java   php   Perl 
 game development   web development   internet   *nix   graphics   hardware 
 telecommunications   C++ 
 Flash   Active Directory   Windows