Edit in JSFiddle

function getDomain(url) {
  var domain;
  //trova e rimuovi i protocolli http, ftp, etc etc...

  if (url.indexOf("://") > -1) {
    domain = url.split('/')[2];
  } else {
    domain = url.split('/')[0];
  }

  //trova e rimuovi eventuale porta
  domain = domain.split(':')[0];

  return domain;
}

//questa pagina
document.getElementById("output").innerHTML += getDomain(window.location.href) + "<br/>";

//altri esempi
document.getElementById("output").innerHTML += getDomain("https://github.com/AndreaLombardo/") + "<br/>";
document.getElementById("output").innerHTML += getDomain("https://www.facebook.com/LeOfferteOnlineOfficial/") + "<br/>";
document.getElementById("output").innerHTML += getDomain("ftps://ftp.websitename.com/dir/file.txt") + "<br/>";
document.getElementById("output").innerHTML += getDomain("websitename.com:1234/dir/file.txt") + "<br/>";
document.getElementById("output").innerHTML += getDomain("https://twitter.com/LeOfferteOnline") + "<br/>";
document.getElementById("output").innerHTML += getDomain("ftps://websitename.com:1234/dir/file.txt") + "<br/>";
<div id="output">

</div>