1(function () { 2 function getScrollY() { 3 return window.pageYOffset || document.documentElement.scrollTop || 0; 4 } 5 6 function initScrollToTop() { 7 const scrollBtn = document.getElementById("scrollToTopBtn"); 8 const scrollWrapper = document.querySelector(".scroll-to-top-wrapper"); 9 if (!scrollBtn || !scrollWrapper) return false; 10 11 let lastScrollY = getScrollY(); 12 let threshold = 4 * window.innerHeight; 13 let scheduled = false; 14 15 function setVisible(isVisible) { 16 scrollWrapper.classList.toggle("is-visible", isVisible); 17 } 18 19 function updateVisibility(currentScrollY) { 20 if (currentScrollY < lastScrollY) { 21 setVisible(false); 22 return; 23 } 24 25 const isScrollingDown = currentScrollY > lastScrollY; 26 setVisible(isScrollingDown && currentScrollY > threshold); 27 } 28 29 function flushFrame() { 30 const currentScrollY = getScrollY(); 31 updateVisibility(currentScrollY); 32 lastScrollY = currentScrollY; 33 scheduled = false; 34 } 35 36 function onScroll() { 37 if (scheduled) return; 38 scheduled = true; 39 requestAnimationFrame(flushFrame); 40 } 41 42 window.addEventListener("scroll", onScroll, { passive: true }); 43 window.addEventListener("resize", () => { 44 threshold = 4 * window.innerHeight; 45 flushFrame(); 46 }); 47 48 scrollBtn.addEventListener("click", () => { 49 window.scrollTo({ top: 0, behavior: "smooth" }); 50 }); 51 52 return true; 53 } 54 55 function startWithObserver() { 56 if (initScrollToTop()) return; 57 58 const observer = new MutationObserver(() => { 59 if (initScrollToTop()) { 60 observer.disconnect(); 61 } 62 }); 63 64 observer.observe(document.documentElement, { childList: true, subtree: true }); 65 setTimeout(() => observer.disconnect(), 15000); 66 } 67 68 if (document.readyState === "loading") { 69 document.addEventListener("DOMContentLoaded", startWithObserver, { once: true }); 70 } else { 71 startWithObserver(); 72 } 73})();
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.