var replaceHostname = function ( url ) {

// Replace the url hostname, if it has a match in the config object

// Also sets port to default, and make sure schema is https

var anchor = document . createElement ( 'a' ) ;

anchor . href = url ;

var originalHostname = anchor . hostname ;

if ( urlConfig [ originalHostname ] ) {

// If url hostname is in config object, replace it

var urlObject = urlConfig [ originalHostname ] ;

var originalPort = anchor . port ;

if ( urlObject [ originalPort ] ) {

// The domains are seperated by different ports

anchor . hostname = urlObject [ originalPort ] ;

anchor . port = 80 ;

anchor . protocol = 'https:' ;

}

return anchor . href ;

}

// return original URL if it doesn't match

return url ;