|
1 | 1 | /*! instant.page v5.1.0 - (C) 2019-2020 Alexandre Dieulot - https://instant.page/license */ |
2 | | -let t,e;const n=new Set,o=document.createElement("link"),i=o.relList&&o.relList.supports&&o.relList.supports("prefetch")&&window.IntersectionObserver&&"isIntersecting"in IntersectionObserverEntry.prototype,s="instantAllowQueryString"in document.body.dataset,a="instantAllowExternalLinks"in document.body.dataset,r="instantWhitelist"in document.body.dataset,c="instantMousedownShortcut"in document.body.dataset,d=1111;let l=65,u=!1,f=!1,m=!1;if("instantIntensity"in document.body.dataset){const t=document.body.dataset.instantIntensity;if("mousedown"==t.substr(0,"mousedown".length))u=!0,"mousedown-only"==t&&(f=!0);else if("viewport"==t.substr(0,"viewport".length))navigator.connection&&(navigator.connection.saveData||navigator.connection.effectiveType&&navigator.connection.effectiveType.includes("2g"))||("viewport"==t?document.documentElement.clientWidth*document.documentElement.clientHeight<45e4&&(m=!0):"viewport-all"==t&&(m=!0));else{const e=parseInt(t);isNaN(e)||(l=e)}}if(i){const n={capture:!0,passive:!0};if(f||document.addEventListener("touchstart",function(t){e=performance.now();const n=t.target.closest("a");if(!h(n))return;v(n.href)},n),u?c||document.addEventListener("mousedown",function(t){const e=t.target.closest("a");if(!h(e))return;v(e.href)},n):document.addEventListener("mouseover",function(n){if(performance.now()-e<d)return;const o=n.target.closest("a");if(!h(o))return;o.addEventListener("mouseout",p,{passive:!0}),t=setTimeout(()=>{v(o.href),t=void 0},l)},n),c&&document.addEventListener("mousedown",function(t){if(performance.now()-e<d)return;const n=t.target.closest("a");if(t.which>1||t.metaKey||t.ctrlKey)return;if(!n)return;n.addEventListener("click",function(t){1337!=t.detail&&t.preventDefault()},{capture:!0,passive:!1,once:!0});const o=new MouseEvent("click",{view:window,bubbles:!0,cancelable:!1,detail:1337});n.dispatchEvent(o)},n),m){let t;(t=window.requestIdleCallback?t=>{requestIdleCallback(t,{timeout:1500})}:t=>{t()})(()=>{const t=new IntersectionObserver(e=>{e.forEach(e=>{if(e.isIntersecting){const n=e.target;t.unobserve(n),v(n.href)}})});document.querySelectorAll("a").forEach(e=>{h(e)&&t.observe(e)})})}}function p(e){e.relatedTarget&&e.target.closest("a")==e.relatedTarget.closest("a")||t&&(clearTimeout(t),t=void 0)}function h(t){if(t&&t.href&&(!r||"instant"in t.dataset)&&(a||t.origin==location.origin||"instant"in t.dataset)&&["http:","https:"].includes(t.protocol)&&("http:"!=t.protocol||"https:"!=location.protocol)&&(s||!t.search||"instant"in t.dataset)&&!(t.hash&&t.pathname+t.search==location.pathname+location.search||"noInstant"in t.dataset))return!0}function v(t){if(n.has(t))return;const e=document.createElement("link");e.rel="prefetch",e.href=t,document.head.appendChild(e),n.add(t)} |
| 2 | +let t, e; |
| 3 | +const n = new Set(), |
| 4 | + o = document.createElement('link'), |
| 5 | + i = |
| 6 | + o.relList && |
| 7 | + o.relList.supports && |
| 8 | + o.relList.supports('prefetch') && |
| 9 | + window.IntersectionObserver && |
| 10 | + 'isIntersecting' in IntersectionObserverEntry.prototype, |
| 11 | + s = 'instantAllowQueryString' in document.body.dataset, |
| 12 | + a = 'instantAllowExternalLinks' in document.body.dataset, |
| 13 | + r = 'instantWhitelist' in document.body.dataset, |
| 14 | + c = 'instantMousedownShortcut' in document.body.dataset, |
| 15 | + d = 1111; |
| 16 | +let l = 65, |
| 17 | + u = !1, |
| 18 | + f = !1, |
| 19 | + m = !1; |
| 20 | +if ('instantIntensity' in document.body.dataset) { |
| 21 | + const t = document.body.dataset.instantIntensity; |
| 22 | + if ('mousedown' == t.substr(0, 'mousedown'.length)) |
| 23 | + ((u = !0), 'mousedown-only' == t && (f = !0)); |
| 24 | + else if ('viewport' == t.substr(0, 'viewport'.length)) |
| 25 | + (navigator.connection && |
| 26 | + (navigator.connection.saveData || |
| 27 | + (navigator.connection.effectiveType && |
| 28 | + navigator.connection.effectiveType.includes('2g')))) || |
| 29 | + ('viewport' == t |
| 30 | + ? document.documentElement.clientWidth * |
| 31 | + document.documentElement.clientHeight < |
| 32 | + 45e4 && (m = !0) |
| 33 | + : 'viewport-all' == t && (m = !0)); |
| 34 | + else { |
| 35 | + const e = parseInt(t); |
| 36 | + isNaN(e) || (l = e); |
| 37 | + } |
| 38 | +} |
| 39 | +if (i) { |
| 40 | + const n = { capture: !0, passive: !0 }; |
| 41 | + if ( |
| 42 | + (f || |
| 43 | + document.addEventListener( |
| 44 | + 'touchstart', |
| 45 | + function (t) { |
| 46 | + e = performance.now(); |
| 47 | + const n = t.target.closest('a'); |
| 48 | + if (!h(n)) return; |
| 49 | + v(n.href); |
| 50 | + }, |
| 51 | + n |
| 52 | + ), |
| 53 | + u |
| 54 | + ? c || |
| 55 | + document.addEventListener( |
| 56 | + 'mousedown', |
| 57 | + function (t) { |
| 58 | + const e = t.target.closest('a'); |
| 59 | + if (!h(e)) return; |
| 60 | + v(e.href); |
| 61 | + }, |
| 62 | + n |
| 63 | + ) |
| 64 | + : document.addEventListener( |
| 65 | + 'mouseover', |
| 66 | + function (n) { |
| 67 | + if (performance.now() - e < d) return; |
| 68 | + const o = n.target.closest('a'); |
| 69 | + if (!h(o)) return; |
| 70 | + (o.addEventListener('mouseout', p, { passive: !0 }), |
| 71 | + (t = setTimeout(() => { |
| 72 | + (v(o.href), (t = void 0)); |
| 73 | + }, l))); |
| 74 | + }, |
| 75 | + n |
| 76 | + ), |
| 77 | + c && |
| 78 | + document.addEventListener( |
| 79 | + 'mousedown', |
| 80 | + function (t) { |
| 81 | + if (performance.now() - e < d) return; |
| 82 | + const n = t.target.closest('a'); |
| 83 | + if (t.which > 1 || t.metaKey || t.ctrlKey) return; |
| 84 | + if (!n) return; |
| 85 | + n.addEventListener( |
| 86 | + 'click', |
| 87 | + function (t) { |
| 88 | + 1337 != t.detail && t.preventDefault(); |
| 89 | + }, |
| 90 | + { capture: !0, passive: !1, once: !0 } |
| 91 | + ); |
| 92 | + const o = new MouseEvent('click', { |
| 93 | + view: window, |
| 94 | + bubbles: !0, |
| 95 | + cancelable: !1, |
| 96 | + detail: 1337, |
| 97 | + }); |
| 98 | + n.dispatchEvent(o); |
| 99 | + }, |
| 100 | + n |
| 101 | + ), |
| 102 | + m) |
| 103 | + ) { |
| 104 | + let t; |
| 105 | + (t = window.requestIdleCallback |
| 106 | + ? (t) => { |
| 107 | + requestIdleCallback(t, { timeout: 1500 }); |
| 108 | + } |
| 109 | + : (t) => { |
| 110 | + t(); |
| 111 | + })(() => { |
| 112 | + const t = new IntersectionObserver((e) => { |
| 113 | + e.forEach((e) => { |
| 114 | + if (e.isIntersecting) { |
| 115 | + const n = e.target; |
| 116 | + (t.unobserve(n), v(n.href)); |
| 117 | + } |
| 118 | + }); |
| 119 | + }); |
| 120 | + document.querySelectorAll('a').forEach((e) => { |
| 121 | + h(e) && t.observe(e); |
| 122 | + }); |
| 123 | + }); |
| 124 | + } |
| 125 | +} |
| 126 | +function p(e) { |
| 127 | + (e.relatedTarget && |
| 128 | + e.target.closest('a') == e.relatedTarget.closest('a')) || |
| 129 | + (t && (clearTimeout(t), (t = void 0))); |
| 130 | +} |
| 131 | +function h(t) { |
| 132 | + if ( |
| 133 | + t && |
| 134 | + t.href && |
| 135 | + (!r || 'instant' in t.dataset) && |
| 136 | + (a || t.origin == location.origin || 'instant' in t.dataset) && |
| 137 | + ['http:', 'https:'].includes(t.protocol) && |
| 138 | + ('http:' != t.protocol || 'https:' != location.protocol) && |
| 139 | + (s || !t.search || 'instant' in t.dataset) && |
| 140 | + !( |
| 141 | + (t.hash && |
| 142 | + t.pathname + t.search == location.pathname + location.search) || |
| 143 | + 'noInstant' in t.dataset |
| 144 | + ) |
| 145 | + ) |
| 146 | + return !0; |
| 147 | +} |
| 148 | +function v(t) { |
| 149 | + if (n.has(t)) return; |
| 150 | + const e = document.createElement('link'); |
| 151 | + ((e.rel = 'prefetch'), |
| 152 | + (e.href = t), |
| 153 | + document.head.appendChild(e), |
| 154 | + n.add(t)); |
| 155 | +} |
0 commit comments