const rootDomain=window.location.hostname;const prefetchInterval=100;const excludedElements=['noprefetch','no-prefetch'];const excludeLinks=['mailto:'];const prefetchedUrls=[];let lastPrefetchTimestamp=0;function canUrlBePrefetched(url){const parsedUrl=new URL(url);if(parsedUrl.search){return!1}
if(parsedUrl.hostname!==rootDomain){return!1}
for(const excludedElement of excludedElements){if(parsedUrl.searchParams.has(excludedElement)||parsedUrl.hash===`#${excludedElement}`||parsedUrl.pathname.includes(excludedElement)){return!1}}
for(const excludeLink of excludeLinks){if(url.includes(excludeLink)){return!1}}
return!0}
function prefetchUrl(url){if(!prefetchedUrls.includes(url)){prefetchedUrls.push(url);const prefetchElement=document.createElement('link');prefetchElement.rel='prefetch';prefetchElement.href=url;document.head.appendChild(prefetchElement)}}
function prefetchUrls(){const links=document.getElementsByTagName('a');const currentTimestamp=Date.now();for(const link of links){const href=link.href.split('#')[0];if(canUrlBePrefetched(href)&&!prefetchedUrls.includes(href)){if(currentTimestamp-lastPrefetchTimestamp>=prefetchInterval){prefetchUrl(href);lastPrefetchTimestamp=currentTimestamp}}}}
function handleMouseHover(event){const target=event.target;if(target.tagName.toLowerCase()==='a'){const href=target.href.split('#')[0];if(canUrlBePrefetched(href)&&!prefetchedUrls.includes(href)){prefetchUrl(href)}}}
window.addEventListener('scroll',prefetchUrls);window.addEventListener('mouseover',handleMouseHover)