Skip to content

Instantly share code, notes, and snippets.

@jgillman
Last active June 28, 2016 23:34
Show Gist options
  • Save jgillman/62c4a9d905fde28584fd to your computer and use it in GitHub Desktop.
Save jgillman/62c4a9d905fde28584fd to your computer and use it in GitHub Desktop.
Domain com to dev toggler

.dev to .com Domain Toggle

This is a javascript bookmarklet that toggles your current domain between a product and local development URL.

For example:

https://example.com/some/path?key=value
Becomes:
http://example.dev/some/path?key=value

Installation

  1. Select the line starting with javascript: from the "dist.js" file and copy it
  2. Create a new bookmark in your bookmark bar (or duplicate an existing one).
  3. Right click on the bookmark in your bookmark bar to Edit it.
  4. Paste the javascript: line in to replace the URL of the bookmark
  5. Profit!
// Copy this to your URL bar:
javascript:!function(){var t=/(.+)(:\/\/.+)(com|dev)/,o=location.origin.match(t),n=o[1],c=o[2],i=o[3],a=location.pathname,r=location.search,e=function(t){return"https"===t?"http":"https"},h=function(t){return"com"===t?"dev":"com"};n=e(n),i=h(i),location.href=[n,c,i,a,r].join("")}();
/*jshint strict:false, browser:true */
(function bookmarklet() {
var re = /(.+)(:\/\/.+)(com|dev)/;
var match = location.origin.match( re );
var protocol = match[1];
var domain = match[2];
var tld = match[3];
var path = location.pathname;
var query = location.search;
var flopProtocol = function( _protocol ) {
if ( _protocol === 'https' ) {
return 'http';
}
else {
return 'https';
}
};
var flopTld = function( _tld ) {
if ( _tld === 'com' ) {
return 'dev';
}
else {
return 'com';
}
};
protocol = flopProtocol( protocol );
tld = flopTld( tld );
location.href = [ protocol, domain, tld, path, query ].join('');
}());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment