Skip to content

Instantly share code, notes, and snippets.

@crccheck
Last active January 26, 2022 17:03
Show Gist options
  • Save crccheck/758791 to your computer and use it in GitHub Desktop.
Save crccheck/758791 to your computer and use it in GitHub Desktop.
Bookmarklet to swap from the live site to my local dev site
javascript:(function(){var a=location.href.split('/');a[0]='http:';a[2]=location.port?'www.texastribune.org':'localhost:8000';window.open(a.join('/'))})();
javascript:(function(){var a=location.href.split('/');a[0]='http:';a[2]=location.port?'www.texastribune.org':'localhost:8000';location.replace(a.join('/'))})();
// UNMINIFIED
// assumes you're running your dev server on a non-80 port
// config the ternary to your own servers
(function(){
var a = location.href.split('/');
a[0] = 'http:';
a[2] = location.port? 'www.texastribune.org' : 'localhost:8000';
window.open(a.join('/'));
})();
@daverau
Copy link

daverau commented Jul 31, 2014

Super handy, thanks for this! I made a (naive) modification that works like a toggle:

(function(){
  var staging = 'staging.site.com',
  live = 'www.site.com',
  a = location.href.split('/');
  if (a[2] === live) {
    a[2] = staging;
  } else if (a[2] === staging) {
    a[2] = live;
  }
  location.replace(a.join('/'));

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment