1var twgSource = function() { 2 this.setCookie = function(name, value, days) { 3 var expires = ""; 4 if (days) { 5 var date = new Date(); 6 date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000)); 7 expires = "; expires=" + date.toUTCString(); 8 } 9 document.cookie = name + "=" + (value || "") + expires + "; path=/"; 10 } 11 12 this.getCookie = function(name) { 13 var nameEQ = name + "="; 14 var ca = document.cookie.split(';'); 15 for (var i = 0; i < ca.length; i++) { 16 var c = ca[i]; 17 while (c.charAt(0) == ' ') c = c.substring(1, c.length); 18 if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length); 19 } 20 return null; 21 } 22 23 this.eraseCookie = function(name) { 24 document.cookie = name + '=; Max-Age=-99999999;'; 25 } 26 27 this.parseUri = function(str) { 28 var o = this.parseOpts, 29 m = o.parser[o.strictMode ? "strict" : "loose"].exec(str), 30 uri = {}, 31 i = 14; 32 33 while (i--) uri[o.key[i]] = m[i] || ""; 34 35 uri[o.q.name] = {}; 36 uri[o.key[12]].replace(o.q.parser, function ($0, $1, $2) { 37 if ($1) uri[o.q.name][$1] = $2; 38 }); 39 40 return uri; 41 }; 42 43 this.parseOpts = { 44 strictMode: false, 45 key: ["source","protocol","authority","userInfo","user","password","host","port","relative","path","directory","file","query","anchor"], 46 q: { 47 name: "queryKey", 48 parser: /(?:^|&)([^&=]*)=?([^&]*)/g 49 }, 50 parser: { 51 strict: /^(?:([^:\/?#]+):)?(?:\/\/((?:(([^:@]*)(?::([^:@]*))?)?@)?([^:\/?#]*)(?::(\d*))?))?((((?:[^?#\/]*\/)*)([^?#]*))(?:\?([^#]*))?(?:#(.*))?)/, 52 loose: /^(?:(?![^:@]+:[^:@\/]*@)([^:\/?#.]+):)?(?:\/\/)?((?:(([^:@]*)(?::([^:@]*))?)?@)?([^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/ 53 } 54 }; 55 var ref = this.parseUri(document.referrer); 56 var site = this.parseUri(document.location); 57 if(ref.host && ref.host!=site.host && !this.getCookie('twg-referrer')) { 58 this.setCookie('twg-referrer',ref.host.replace("www.",""),30) 59 } 60 61 if(site.queryKey.gclid) { 62 if(site.queryKey.keyword) { 63 this.setCookie('twg-referrer',"Google AdWords - Keyword: "+site.queryKey.keyword,30) 64 } else { 65 this.setCookie('twg-referrer',"Google AdWords",30) 66 } 67 } 68 if(this.getCookie('twg-referrer')) { 69 jQuery('.twgSource-field').find("input").val(this.getCookie('twg-referrer')).trigger('change'); 70 } else { 71 jQuery('.twgSource-field').find("input").val("Direct/No Source").trigger('change'); 72 } 73}; 74twgSource();
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.