-function extractDomain(url, y) {
- var domain;
-
- //remove protocol
- if (url.indexOf("://") > -1) {
- domain = url.split('/')[2];
- }
- else {
- domain = url.split('/')[0];
- }
-
- //remove port number
- domain = domain.split(':')[0];
-
- if (y == 1) {
-
- d = splitHostname(domain);
-
- if (d.subdomain != "www" && d.subdomain != "") {
- return d.subdomain;
- }
- else {
- return d.domain;
- }
-
- } else {
- return domain;
- }
-}
-
-function addhttp(url) {
- if (!/^(f|ht)tps?:\/\//i.test(url)) {
- url = "http://" + url;
- }
- return url;
-}
-
-function splitHostname(h) {
- var result = {};
- var urlParts = new RegExp('([a-z\-0-9]{2,63})\.([a-z\.]{2,5})$').exec(h);
- if (urlParts == null) {
- console.log("Error formatting link " + h);
- return "";
- }
- result.domain = urlParts[1];
- result.type = urlParts[2];
- result.subdomain = h.replace(result.domain + '.' + result.type, '').slice(0, -1);;
- return result;
-}