-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpage.33c44e88.js
1 lines (1 loc) · 1.62 KB
/
page.33c44e88.js
1
function m(e){e=e||1;var t=[],r=0;function o(a){t.push(a)>1||n()}function s(){r--,n()}function n(){r<e&&t.length>0&&(t.shift()(),r++)}return[o,s]}function v(e,t){const r=t?.timeout??50,o=Date.now();return setTimeout(function(){e({didTimeout:!1,timeRemaining:function(){return Math.max(0,r-(Date.now()-o))}})},1)}const w=window.requestIdleCallback||v;var p=w;const u=["mouseenter","touchstart","focus"],l=new Set,f=new Set;function y({href:e}){try{const t=new URL(e);return window.location.origin===t.origin&&window.location.pathname!==t.pathname&&!l.has(e)}catch{}return!1}let i,c;function b(e){l.add(e.href),c.observe(e),u.map(t=>e.addEventListener(t,d,{passive:!0,once:!0}))}function g(e){c.unobserve(e),u.map(t=>e.removeEventListener(t,d))}function d({target:e}){e instanceof HTMLAnchorElement&&h(e)}async function h(e){g(e);const{href:t}=e;try{const r=await fetch(t).then(n=>n.text());i=i||new DOMParser;const o=i.parseFromString(r,"text/html"),s=Array.from(o.querySelectorAll('link[rel="stylesheet"]'));await Promise.all(s.filter(n=>!f.has(n.href)).map(n=>(f.add(n.href),fetch(n.href))))}catch{}}function A({selector:e='a[href][rel~="prefetch"]',throttle:t=1}){const r=navigator.connection;if(typeof r<"u"){if(r.saveData)return Promise.reject(new Error("Cannot prefetch, Save-Data is enabled"));if(/2g/.test(r.effectiveType))return Promise.reject(new Error("Cannot prefetch, network conditions are poor"))}const[o,s]=m(t);c=c||new IntersectionObserver(n=>{n.forEach(a=>{a.isIntersecting&&a.target instanceof HTMLAnchorElement&&o(()=>h(a.target).finally(s))})}),p(()=>{const n=Array.from(document.querySelectorAll(e)).filter(y);for(const a of n)b(a)})}A({});