Last active
September 29, 2017 11:45
-
-
Save matthendrix/a2d1713b019f94d65f2cd3608833a4c0 to your computer and use it in GitHub Desktop.
A bookmarklet that can switch between local and live servers.
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
javascript:(function(){ | |
var matches = { | |
'domain1':'www.domain1.com.au', | |
'whatever':'www.whatever.com.au', | |
'mylocalserver':'www.myliveserver.com.au' | |
}, | |
matchesReversed = {}; | |
for(var v in matches) { | |
matchesReversed[matches[v]] = v; | |
} | |
if(typeof matches[window.location.hostname] !== 'undefined') { | |
window.location.href = window.location.href.replace(window.location.hostname, matches[window.location.hostname]); | |
} | |
else if(typeof matchesReversed[window.location.hostname] !== 'undefined') { | |
var href = window.location.href.replace(window.location.hostname, matchesReversed[window.location.hostname]); | |
window.location.href = href.replace('https', 'http'); | |
} | |
else { | |
alert("The hostname \""+ window.location.hostname +"\" was not matched."); | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment