The Code
Much like a bookmarklet , 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
TIP
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.