1// On identifie le user grâce à un token unique 2var cookie = getCookie('mad-user-token'); 3var path = window.location.href.replace(/^(?:\/\/|[^/]+)*\//, ''); 4var session = ajax_var.session_id; 5var referrer = document.referrer; 6 7step1(); 8// Ãtape 1 : Identifier le user 9function step1() { 10 if (cookie) { // Returning user 11 12 // Si le referrer est le site actuel, c'est simplement que l'utilisateur a changé de page alors on ne garde pas le referrer 13 if (document.referrer.indexOf(location.protocol + "//" + location.host) === 0) { 14 referrer = false; 15 } 16 17 step2(); 18 } 19 20 else{ // New user, go get the cookie 21 22 $.ajax({ 23 url: ajax_var.url, 24 type : "post", 25 dataType : "json", 26 data: {action: "mad_get_token",nonce: ajax_var.nonce} 27 }).done(function(data) { 28 cookie = data.token; 29 setCookie('mad-user-token',cookie,1); 30 step2(); 31 }); 32 33 } 34} 35 36// Ãtape 2 : Envoyer les informations nécessaires (l'url consulté et le referrer si pertinent) au système 37function step2() { 38 var values = {path:path}; 39 if (referrer) { 40 values.referrer = referrer; 41 } 42 var data = { 43 action: 'mad_add', 44 nonce: ajax_var.nonce, 45 user_token: cookie, 46 session_token: session, 47 values: values 48 }; 49 50 $.ajax({ 51 url: ajax_var.url, 52 type : "post", 53 dataType : "json", 54 data: data 55 }).done(function(data) { 56 57 }); 58} 59 60 61function setCookie(cname, cvalue, exdays) { 62 var d = new Date(); 63 d.setTime(d.getTime() + (exdays * 24 * 60 * 60 * 1000)); 64 var expires = "expires="+d.toUTCString(); 65 document.cookie = cname + "=" + cvalue + ";" + expires + ";path=/"; 66} 67 68function getCookie(cname) { 69 var name = cname + "="; 70 var ca = document.cookie.split(';'); 71 72 for (var i = 0; i < ca.length; i++) { 73 var c = ca[i]; 74 while (c.charAt(0) == ' ') { 75 c = c.substring(1); 76 } 77 78 if (c.indexOf(name) == 0) { 79 return c.substring(name.length, c.length); 80 } 81 } 82 return ""; 83} 84 85function checkCookie() { 86 var user = getCookie("username"); 87 if (user != "") { 88 alert("Welcome again " + user); 89 } else { 90 user = prompt("Please enter your name:", ""); 91 if (user != "" && user != null) { 92 setCookie("username", user, 365); 93 } 94 } 95}
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.