You cannot in general terms add JavaScript to a web page coming from another server. You can inject the JavaScript by creating your own page on your file system. That page would need to have a frame to host the yahoo page. Since you JavaScript would be on the parent it could overwrite the urls in the child page.
You can create what are called content scripts (and content styles). Content scripts have their own private JavaScript namespace but have full access to the DOM of the current page. They are basically Greasemonkey scripts, except you don't need Greasemonkey. Content scripts are a great way to consume web content on your terms, not those of the stinkin' content provider!
A typical scenario is, a website you visit often has useful content but runs an overactive ad-tech engine in the background that spins up your CPU fans and makes simple scrolling laggy. The solution? Turn off JavaScript for the site. Now everything is quiet, and the site responds instantly. Except videos don't work. Comments are not visible. In extreme cases, the site may be a blank white page.
So, to work. A little reverse engineering and content script coding can restore the essential features disabled by disabling JavaScript (JavaScript disabling does not apply to content scripts ;)), and you end up with a responsive, useful site!
Using the content script mechanism, you can also inject styles to a page. Say, there is an obnoxious navigation/ad bar stuck at the top of the screen. You can delete it, or make it scroll off normally. No JavaScript necessary. Just target it with the appropriate CSS declarations !important.
See here to get started.
Content scripts are a major part of browser extensions.