function (url, filter){ if (!url || (url.length < 1)) return false; if (!filter || !(filter instanceof Array)) return false; var parts = url.split('/'); if ((parts == null) || (parts.length < 3)) return false; var domain = parts[2]; for (var i = 0; i < filter.length; i++) { if (domain.indexOf(filter[i]) != -1) return true; } return false;};searchshield.GetDomain = function (url){ if (url != null) { // get url domain var parts = url.split('/'); if ((parts != null) && (parts.length >= 3)) { return parts[2].toLowerCase(); } } return url;};searchshield.getUrlContents = function (url) { if (url == null) return null; // don't query if local url if (url.indexOf("linkscanner://") != -1) return null; try { req = new XMLHttpRequest(); req.open("GET", url, false); req.send(null); if (req.status == 200) return req.responseText; else return null; } catch (err) { // nothing to do return null; }};searchshield.parseLink = function (href, simpleMode){ var uri = {}; var parameter = { complex: { pattern: /^(?:([a-z]+):(?:([a-z]*):)?\/\/)?(?:([^:@]*)(?::([^:@]*))?@)?((?:[a-z0-9_-]+\.)+[a-z]{2,})(?::(\d+))?(?:([^:\?\#]+))?(?:\?([^\#]+))?(?:\#([^\s]+))?$/i, element: ['source','scheme','subscheme','user','pass','host','port','path','query','fragment'] }, simple: { pattern: /^(?:([a-z]+):\/\/)?((?:[a-z0-9_-]+\.)+[a-z]{2,})(?:\/)([^:\?]+)?(?:([\?|\#])([^\?]+))?$/i, element: ['source','scheme','host','path','delimiter','query'] } }; var mode = simpleMode !== false ? 'simple' : 'complex'; var pattern = parameter[mode].pattern; var element = parameter[mode].element; if (!href) return uri; var matches = href.match(pattern); if (matches) { // -------------------- // iterate over the matches array and populate uri properties // using the respective element parameter as the name. // NOTE: set raw property type as String to make inArray() // work properly with instanceof. // -------------------- for (var i=0; i < matches.length; i++) uri[element[i]] = new String(matches[i] || ""); // -------------------- // create an array, hostArray, from host, for example, // host="www.google.com" and hostArray=["www","google","com"] // -------------------- uri.hostArray = uri.host.split("."); // -------------------- // create an array, qsArray, from query, for example, // query='hl=en&q=javascript&btnG=Search&aq=f&aqi=g10&aql=&oq=&gs_rfai=' // qsArray=[{hl:'en'},{q:javascript}, ... ,(qs_rfai:''}] // // $0=entire match, $1=capture 1, $2=capture 2 // must include $0 even though it is unused so // the replace works properly // -------------------- uri.qsArray = searchshield.parseQuery(uri.query); } //non-standard urls require a fail-safe that relies on simply splitting the href function splitLink(href) { // split the href on '/' var linkParts = href.split("/"); // need domain and path if ((linkParts == null) || (linkParts.length < 2)) return false; var uri = { delimiter: (linkParts[3]).substring(0,1), host: linkParts[2], hostArray: (linkParts[2]).split('.'), path: (linkParts[3]).substring(1), qsArray: [], query: '', scheme: (linkParts[0]).substring(0, linkParts[0].length-1), source: href }; return uri; } if (!uri.host) uri = splitLink(href); return uri;};searchshield.parseQuery = function (qs){ var qsArray = []; qs.replace(/(?:^|&)([^&=]*)=?([^&]*)/g, function ($0, $1, $2) { if ($1) qsArray[$1] = $2; } ); return qsArray;};// general functionssearchshield.arrayKeys = function (array){ var keys = new Array(); for(k in array) keys.push(k); return keys;};searchshield.inArray = function (key, array, caseSensitive, exactMatch){ if (! array instanceof Array) return false; if (caseSensitive !== true) caseSensitive = false; if (exactMatch !== false) exactMatch = true; if (key instanceof String) { for (var i=0; i < array.length; i++) { var k = caseSensitive ? key.valueOf() : key.valueOf().toLowerCase(); var a = caseSensitive ? array[i] : array[i].toLowerCase(); if(exactMatch && k === a) return true; else if (!exactMatch && (-1 !== k.indexOf(a))) return true; } } else if (key instanceof Array) { for (var i=0; i < array.length; i++) for (var