Skip to content

Instantly share code, notes, and snippets.

@thisislawatts
Last active August 29, 2015 14:02
Show Gist options
  • Save thisislawatts/8e0939756ea97e057627 to your computer and use it in GitHub Desktop.
Save thisislawatts/8e0939756ea97e057627 to your computer and use it in GitHub Desktop.
Tiny Bookmarklet for swapping between sites
(function(w) {
var HotSwap = function () {
this.version = 2;
this.storageKey = 'LAHotSwapTarget_' + this.version;
}
HotSwap.prototype.init = function() {
var dest = window.localStorage.getItem( this.storageKey );
if ( !dest ) {
dest = prompt ("No target domain found", window.location.host.replace('www\.','') );
if (!dest) return;
window.localStorage.setItem( this.storageKey , 'http://' + dest);
}
this.navigateTo( dest + window.location.pathname + window.location.search );
}
HotSwap.prototype.navigateTo = function(url) {
if (!url.match(/^http/))
url = '//' + url;
window.location = url;
}
HotSwap.prototype.isLocal = function() {
return window.location.host.match('.dev');
}
w.LAHotSwap = new HotSwap();
w.LAHotSwap.init();
}(window));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment