1const Counter = (function() { 2 3 const setClass = 'counted' 4 const collection = document.querySelectorAll('.count-this:not(.' + setClass + ')') 5 let isScrollingRef 6 7 const handleScrollCheck = () => { 8 clearTimeout(isScrollingRef) 9 10 isScrollingRef = setTimeout(() => { 11 12 collection.forEach((ele, ind) => { 13 if(elementIsVisibleInViewport(ele) && !ele.classList.contains(setClass)) { 14 15 let start = (ele.dataset.startCount == undefined) ? 0 : ele.dataset.startCount 16 const end = parseInt(ele.innerHTML.replace(/\,/g,''), 10) 17 18 let counting = setInterval(updateCount) 19 20 function updateCount() { 21 ele.classList.add(setClass) 22 const currentCount = start = (start > end-1000) ? start + 1 : start + 1001 23 24 ele.innerHTML = currentCount.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ","); 25 ele.dataset.startCount = currentCount 26 27 if (start >= end) { 28 clearInterval(counting) 29 } 30 } 31 } 32 }) 33 34 }, 30) 35 36 } 37 38 window.addEventListener('scroll', handleScrollCheck) 39 40 return { 41 init: function() { 42 handleScrollCheck() 43 } 44 } 45 46})(); 47 48(function() { 49 Counter.init(); 50})();
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.