Etract data from URL address.  (JavaScript)
Leetness: -5  

// Returns an object with parts of the URL address:
// protocol, root domain name (wwithout 'www'), port, page path, file-name, search part, and hash
function urlData(url) {
  // object for data that will be returned
  var redata = {protocol: '', domain: '', port: 80, path: '', file: '', search: '', hash: ''};

  // creates an anchor element, and adds the url in "href" attribute
  var a_elm  = document.createElement('a');
  a_elm.href = url;

  // adds URL data in redata object, and returns it
  redata.protocol = a_elm.protocol.replace(':', '');
  redata.domain = a_elm.hostname.replace('www.', '');
  if(a_elm.port != '') redata.port = a_elm.port;
  redata.path = a_elm.pathname;
  if(a_elm.pathname.match(/[^\/]+[\.][a-z0-9]+$/i) != null) redata.file = a_elm.pathname.match(/[^\/]+[\.][a-z0-9]+$/i);
  redata.search = a_elm.search.replace('?', '');
  redata.hash = a_elm.hash.replace('#', '');
  return redata;
}

     
Submitted on July 10, 2013 by Anonymous
From: http://coursesweb.net/javascript/