1// modified to work without type="module" 2 3;(function () { 4 /*! instant.page v1.2.2 - (C) 2019 Alexandre Dieulot - https://instant.page/license */ 5 6 var urlToPreload 7 var mouseoverTimer 8 var lastTouchTimestamp 9 10 var prefetcher = document.createElement('link') 11 var isSupported = prefetcher.relList && prefetcher.relList.supports && prefetcher.relList.supports('prefetch') 12 var isDataSaverEnabled = navigator.connection && navigator.connection.saveData 13 var allowQueryString = 'instantAllowQueryString' in document.body.dataset 14 var allowExternalLinks = 'instantAllowExternalLinks' in document.body.dataset 15 16 if (isSupported && !isDataSaverEnabled) { 17 prefetcher.rel = 'prefetch' 18 document.head.appendChild(prefetcher) 19 20 var eventListenersOptions = { 21 capture: true, 22 passive: true 23 } 24 document.addEventListener('touchstart', touchstartListener, eventListenersOptions) 25 document.addEventListener('mouseover', mouseoverListener, eventListenersOptions) 26 } 27 28 function touchstartListener (event) { 29 /* Chrome on Android calls mouseover before touchcancel so `lastTouchTimestamp` 30 * must be assigned on touchstart to be measured on mouseover. */ 31 lastTouchTimestamp = performance.now() 32 33 var linkElement = event.target.closest('a') 34 35 if (!isPreloadable(linkElement)) { 36 return 37 } 38 39 linkElement.addEventListener('touchcancel', touchendAndTouchcancelListener, { passive: true }) 40 linkElement.addEventListener('touchend', touchendAndTouchcancelListener, { passive: true }) 41 42 urlToPreload = linkElement.href 43 preload(linkElement.href) 44 } 45 46 function touchendAndTouchcancelListener () { 47 urlToPreload = undefined 48 stopPreloading() 49 } 50 51 function mouseoverListener (event) { 52 if (performance.now() - lastTouchTimestamp < 1100) { 53 return 54 } 55 56 var linkElement = event.target.closest('a') 57 58 if (!isPreloadable(linkElement)) { 59 return 60 } 61 62 linkElement.addEventListener('mouseout', mouseoutListener, { passive: true }) 63 64 urlToPreload = linkElement.href 65 66 mouseoverTimer = setTimeout(function () { 67 preload(linkElement.href) 68 mouseoverTimer = undefined 69 }, 65) 70 } 71 72 function mouseoutListener (event) { 73 if (event.relatedTarget && event.target.closest('a') === event.relatedTarget.closest('a')) { 74 return 75 } 76 77 if (mouseoverTimer) { 78 clearTimeout(mouseoverTimer) 79 mouseoverTimer = undefined 80 } else { 81 urlToPreload = undefined 82 stopPreloading() 83 } 84 } 85 86 function isPreloadable (linkElement) { 87 if (!linkElement || !linkElement.href) { 88 return 89 } 90 91 if (urlToPreload === linkElement.href) { 92 return 93 } 94 95 var preloadLocation = new URL(linkElement.href) 96 97 if (!allowExternalLinks && preloadLocation.origin !== location.origin && !('instant' in linkElement.dataset)) { 98 return 99 } 100 101 if (!['http:', 'https:'].includes(preloadLocation.protocol)) { 102 return 103 } 104 105 if (preloadLocation.protocol === 'http:' && location.protocol === 'https:') { 106 return 107 } 108 109 if (!allowQueryString && preloadLocation.search && !('instant' in linkElement.dataset)) { 110 return 111 } 112 113 if (preloadLocation.hash && preloadLocation.pathname + preloadLocation.search === location.pathname + location.search) { 114 return 115 } 116 117 if ('noInstant' in linkElement.dataset) { 118 return 119 } 120 121 return true 122 } 123 124 function preload (url) { 125 prefetcher.href = url 126 } 127 128 function stopPreloading () { 129 prefetcher.removeAttribute('href') 130 } 131})()
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.