Skip to content

Instantly share code, notes, and snippets.

@matthendrix
Last active September 29, 2017 11:45
Show Gist options
  • Save matthendrix/a2d1713b019f94d65f2cd3608833a4c0 to your computer and use it in GitHub Desktop.
Save matthendrix/a2d1713b019f94d65f2cd3608833a4c0 to your computer and use it in GitHub Desktop.
A bookmarklet that can switch between local and live servers.
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