1'use strict'; 2 3/** 4 * AJAX 5 * 6 * DESC: Count: 7 * - page visit - (page not refreshed) 8 * - website total visits - including page refresh 9 * - display response messages in dev tools/console 10 * 11 * @since 1.0.0 12 */ 13var StrCPVisitsAjaxCount = function ($) { 14 15 var zeroPad = function zeroPad(num, places) { 16 return String(num).padStart(places, '0'); 17 }; 18 19 // DISPLAY STATUSES. 20 console.log("âââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ"); 21 // JS STATUS. 22 console.log('Strongetic Page Visits Counter Lite - JS status = OK'); 23 24 // PHP STATUS. 25 if (typeof StrCPVisits_page_data === "undefined") { 26 console.log('Strongetic Page Visits Counter Lite - PHP status = FALSE'); 27 } else { 28 console.log('Strongetic Page Visits Counter Lite - PHP status = OK'); 29 } 30 console.log("âââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââââ"); 31 32 $.ajax({ 33 url: STR_CPVISITS.ajax_url, 34 type: 'POST', 35 data: { 36 action: 'StrCPVisits_update_total_visits', 37 page_data: StrCPVisits_page_data, 38 security: STR_CPVISITS.security 39 }, 40 success: function success(response) { 41 // console.log(response); 42 43 // wp_send_json_success. 44 if (response.success === true) { 45 handleResponse(response.data); 46 } 47 } 48 }); // ! $.ajax 49 50 51 function handleResponse(data) { 52 53 // Display page title. 54 console.log("==================================================================="); 55 if (typeof StrCPVisits_page_data !== "undefined") { 56 console.log(STR_CPVISITS.text_page_name + ": " + StrCPVisits_page_data.title + ""); 57 } else { 58 console.log(STR_CPVISITS.text_cannot_access_page_name); 59 } 60 console.log("==================================================================="); 61 62 // DISPLAY MESSAGE. 63 if (typeof data.msg != "undefined") { 64 console.log(STR_CPVISITS.text_message + ": " + data.msg); 65 } 66 67 // DISPLAY NOT COUNTING MESSAGE - only when logged in with not counting user role. 68 if (typeof data.msg_not_counting_the_page != "undefined") { 69 console.log("-------> " + data.msg_not_counting_the_page); 70 } 71 72 // DISPLAY TOTAL PAGE VISITS - on refresh. 73 if (typeof data.page_visits_on_refresh != "undefined" && data.page_visits_on_refresh != null && data.page_visits_on_refresh != "") { 74 console.log(STR_CPVISITS.text_total_page_visits + ': ' + data.page_visits_on_refresh); 75 updatePageCounter(data.page_visits_on_refresh); 76 } 77 78 // DISPLAY TOTAL PAGE VISITS. 79 if (typeof data.page_visits != "undefined" && data.page_visits != null && data.page_visits != "") { 80 if (typeof data.page_visits.nr != "undefined") { 81 if (data.page_visits.nr == null || data.page_visits.nr == "") { 82 console.log(STR_CPVISITS.text_total_page_visits + ": N/A"); 83 } else { 84 console.log(STR_CPVISITS.text_total_page_visits + ": " + data.page_visits.nr); 85 updatePageCounter(data.page_visits.nr); 86 } 87 } 88 } 89 90 // DISPLAY TOTAL VISITS. 91 if (typeof data.total_visits != "undefined") { 92 if (typeof data.total_visits.nr != "undefined") { 93 console.log(STR_CPVISITS.text_total_website_visits + ": " + data.total_visits.nr); 94 updateWebsiteCounter(data.total_visits.nr); 95 } 96 } 97 console.log("==================================================================="); 98 } 99 100 function updatePageCounter(nr) { 101 nr = zeroPad(nr, 5); 102 $('#strcpv-page-counter').html("<p>" + nr + "</p>"); 103 } 104 105 function updateWebsiteCounter(nr) { 106 nr = zeroPad(nr, 5); 107 $('#strcpv-website-counter').html("<p>" + nr + "</p>"); 108 } 109}(jQuery);
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.