1(function( $ ) { 2 window.cachebreak = 1; 3 4 function getAnchor(element, textOnly = false) { 5 var anchor = element.innerText; 6 if ( anchor.length == 0 && textOnly == false) { 7 anchor = element.innerHTML.trim(); 8 if ( typeof( element.children ) !== 'undefined') { 9 if ( element.children.length > 0 ) { 10 if ( element.children[0].tagName == 'IMG' ) { 11 anchor = 'image:' + element.children[0].src; 12 } 13 } 14 } 15 } 16 return anchor; 17 } 18 19 function processAs() { 20 if (showClickCounts()) { 21 var data = new FormData(); 22 data.append("postID", getPostID()); 23 data.append("location", window.location); 24 var url = getHomeURL() + '/wp-json/track-the-click/v3/getpagelinkclicks/' + window.cachebreak++; 25 26 jQuery.ajax({ 27 url: url, 28 type: "POST", 29 data: data, 30 contentType: false, 31 processData: false, 32 cache: false, 33 beforeSend: function ( xhr ) { 34 xhr.setRequestHeader( 'X-WP-Nonce', ajax_var.nonce ); 35 }, 36 success: function(newdata) { 37 if (newdata !== false) { 38 var as = document.getElementsByTagName("a"); 39 Array.from(as, a => { 40 newdata.forEach(clickCount => { 41 if (a.href == clickCount.target && getAnchor(a) == clickCount.anchor && clickCount.clicks > 0) { 42 a.setAttribute("data-clicks", clickCount.clicks); 43 } 44 }); 45 }); 46 } 47 }, 48 error: function(error) { 49 console.error(error); 50 } 51 }); 52 } 53 } 54 55 function bubbleBeacon(event) { 56 if (event.target.closest('A')) { 57 var closestA = event.target.closest('A'); 58 // There is an A at or above this level in the DOM 59 // ie. they've clicked a link 60 var data = new FormData(); 61 data.append("postID", getPostID()); 62 data.append("location", window.location); 63 data.append("anchor", getAnchor(closestA)); 64 data.append("target", closestA.href); 65 var url = getHomeURL() + '/wp-json/track-the-click/v3/click/' + window.cachebreak++; 66 navigator.sendBeacon(url, data); 67 } 68 } 69 70 if (document.readyState === 'loading') { 71 document.addEventListener("DOMContentLoaded", processAs); 72 } else { 73 processAs(); 74 } 75 document.addEventListener("click", bubbleBeacon); 76 document.addEventListener("auxclick", bubbleBeacon); 77})();
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.