Last active
October 3, 2016 14:24
-
-
Save aniket91/464ed8f61ecdeec7cf99ae65ea6514c9 to your computer and use it in GitHub Desktop.
GM script to redirect a URL to new URL
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name PageRedirectScript | |
// @include http://domain1/* | |
// @include https://domain1/* | |
// @run-at document-start | |
// @description Redirects page from one domain to another. Note if domain1 is down you need to add entry in /etc/hosts file as "ipOfDomain2 domain1 domain2". You can get the ipOfDomain2 as "ping domain2" | |
// @namespace http://opensourceforgeeks.blogspot.in/ | |
// @version 1 | |
// @grant none | |
// ==/UserScript== | |
console.log ("Executing PageRedirectScript"); | |
reloadPage(); | |
function reloadPage() { | |
var currentUrl = window.location.href; | |
console.log ("Current URL : " + currentUrl); | |
if(currentUrl.includes("domain1")) { | |
currentUrl = currentUrl.replace("domain1","domain2"); | |
console.log ("New URL : " + currentUrl); | |
//replace() puts the good page in the history instead of the bad page | |
window.location.replace (currentUrl); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment