gauda / Switch Development/Production server

// ==UserScript==
// @name        Switch Development/Production server
// @namespace   gauda
// @description Solely for my own development
// @version     5
// @license     MIT
// @grant       GM.openInTab
// ==/UserScript==

function newUri(){
  uri = new window.URL(document.location);
  if(uri.hostname.match(/\.localhost$/)) {
    uri.protocol = 'https:';
    uri.hostname = uri.hostname.replace(/\.localhost/, '');
  } else {
    uri.protocol = 'http:';
    uri.hostname = uri.hostname + '.localhost';
  }
  return uri.toString();
}

document.addEventListener('keydown', function (e) {
  if (e.keyCode == 88 && e.shiftKey && e.ctrlKey && e.altKey && !e.metaKey) {
    // keyCode for Ctrl + Shift + Alt + x
    GM.openInTab(newUri());
  } else if (e.keyCode == 88 && e.shiftKey && e.ctrlKey && !e.altKey && !e.metaKey) {
    // keyCode for Ctrl + Shift + x
    document.location = newUri();
  }
}, false);