I want to redirect a URL to a different URL. For example, if I were to type in:
google.com
and hit enter, it should redirect me to:
yahoo.com
I was at a previous thread and found a code for this, but unfortunately, it works on ALL URLs, which I don’t want. Also, once the redirect is complete (at yahoo.com) the page will reload again, endlessly looping.
EDIT: Current Code:
// ==UserScript==
// @name Google to Yahoo
// @description Redirects Google to Yahoo
// @include http://*.google.*/*
// @version 1
// ==/UserScript==
if(content.document.location == "http://google.com"){
window.location.replace("http://yahoo.com")
}
The script that you posted simply forwards the user, it never checks what page the user is loading. Since Greasemonkey is Javascript, you can use just get the URL of the current page and compare it.
Get the URL with
And then compare it. I think it would go like this:
edit
Going on what Shoaib said, you can use the include directive in a Greasemonkey script. So, at the top you would put
This would run the script on every google subdomain in every country on every page and no others.
edit 2
Using the namespace directive would make it: